How to get the value of a user or model parameter

Top  Previous  Next

Here is some code to get the value of a user parameter in an Inventor part:

 

double GetUserParameterValueByName (CComPtr<PartComponentDefinition>& pPartCompDef,

                                   const CString& kcsUserParamName)

{

   // Parameters contains two lists, Model and User...

   CComPtr<Parameters> pParameters ;

   pPartCompDef->get_Parameters (&pParameters) ;

 

   // Get the model parameters list...

   CComPtr<UserParameters> pUserParameters ;

   pParameters->get_UserParameters (&pUserParameters) ;

 

   // Find the one we are looking for...

   const UINT ikNumUserParams = pUserParameters->Count ;

 

   for (UINT i = 1 ; i <= ikNumUserParams ; i++) {

       CComPtr<UserParameter> pUserParam ;

       pUserParameters->get_Item (CComVariant(i),&pUserParam) ;

 

       CComBSTR bstrParamName;

       pUserParam->get_Name (&bstrParamName) ;

 

       if (kcsUserParamName.CompareNoCase(CString(bstrParamName)) == 0) {

           // Found it

           VARIANT ParamValue ;

           pUserParam->get_Value (&ParamValue) ;

           return ParamValue.dblVal;

       }

   }

 

   // This is an error

 

   return 0.0;

}

 

 

And here is the very similar code for getting a model parameter value:

 

 

double GetModelParameterValueByName (CComPtr<PartComponentDefinition>& pPartCompDef,

                                    const CString& kcsModelParamName)

{

   // Parameters contains two lists, Model and User...

   CComPtr<Parameters> pParameters ;

   pPartCompDef->get_Parameters (&pParameters) ;

 

   // Get the model parameters list...

   CComPtr<ModelParameters> pModelParameters ;

   pParameters->get_ModelParameters (&pModelParameters) ;

 

   // Find the one we are looking for...

   const UINT ikNumModelParams = pModelParameters->Count ;

   for (UINT i = 1 ; i <= ikNumModelParams ; i++) {

       CComPtr<ModelParameter> pModelParam ;

       pModelParameters->get_Item (CComVariant(i),&pModelParam) ;

 

       CComBSTR bstrParamName;

       pModelParam->get_Name (&bstrParamName) ;

 

       if (kcsModelParamName.CompareNoCase(CString(bstrParamName)) == 0) {

           // Found it

           VARIANT ParamValue ;

           pModelParam->get_Value (&ParamValue) ;

           return ParamValue.dblVal;

       }

   }

 

   // This is an error

 

   return 0.0;

}

 

 

See also Model and User parameters programatically.

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