Get user parameters using C#

Top  Previous  Next

Here's how to do it:

 

       // Returns the string value of the user parameter named in the input

       static string GetUserParam (Inventor.AssemblyDocument InvIAMDoc, string sUserParamName)

       {

           UserParameters UsrParams = InvIAMDoc.ComponentDefinition.Parameters.UserParameters;

 

           int iNumUsrParms = UsrParams.Count;

 

           for (int mp = 1; mp <= iNumUsrParms; mp++)

           {

               // Get this user parameter

               UserParameter UsrParam = UsrParams[mp];

 

               // Compare its name to what we are looking for

               bool bIsMyParam = (string.Compare(UsrParam.Name, sUserParamName, StringComparison.OrdinalIgnoreCase) == 0);

 

               // Return the value if it is the one...

               if (bIsMyParam)

               {

                   string sMsg = string.Format("Found {0} with value {1} ", UsrParam.Name.ToString(), UsrParam.Value.ToString());

                   Debug.WriteLine(sMsg);

                   return UsrParam.Value;

               }

           }

 

           return "";

       }

 

 

 

Text, images and diagrams © 2021 Owen F. Ransen. All rights reserved. (But copy the source code as much as you want!)