How to get the parameters of an assembly or part

Top  Previous  Next

If you have an assembly with parameters you can get hold of the parameters programatically like this:

 

   CComPtr <AssemblyComponentDefinition> pAssCompDef ;

   pAssemblyDoc->get_ComponentDefinition (&pAssCompDef) ;

 

   CComPtr <Parameters> pParams ;

   pAssCompDef->get_Parameters (&pParams) ;

 

   const long ikNumParams = pParams->Count ;

 

   TRACE (L"There are %d params in %s\n",ikNumParams,pszOccName) ;

 

   for (int i = 1 ; i <= ikNumParams ; i++) {

       CComPtr <Parameter> pParam ;

       pParams->get_Item (CComVariant(i),&pParam) ;

 

       VARIANT VarValue ;

       pParam->get_Value (&VarValue) ;

       VarValue.dblVal ;

 

       CComBSTR bstrParamName ;

       pParam->get_Name (&bstrParamName) ;

       TRACE (L"  param %d is called %s and has a value of %.3f= \n",i,bstrParamName,VarValue.dblVal ) ;

   }

 

Notice how the parameter data is picked up inside the for loop.

 

If you have a part occurrence inside an assembly and want to get the parameters of that part a occurrence you can use this:

 

   CComPtr<ComponentDefinition> pCompDef = nullptr ;

   hRes = pCompOcc->get_Definition (&pCompDef) ;

   if (FAILED(hRes) || (pCompDef == nullptr)){

       return ReturnAndShowCOMError(hRes,L"ShowComponentOccurrenceParameters, get_Definition failed.");

   }

 

   TRACE (L"The type of this occurrence is %d, def is %d\n",pCompOcc->GetType(),pCompDef->GetType()) ;

 

   CComPtr<Parameters> pParams;

   CComQIPtr<PartComponentDefinition> pPartCompDef = pCompOcc->Definition;

   if (!pPartCompDef) {

       return (E_FAIL) ;

   }

 

   if (pPartCompDef->IsiPartFactory) {

       TRACE (L"Is an ipart factory\n") ;

   }

 

   // It is a part component definition, so we can get the

   // parameters of the part definition

   pParams = pPartCompDef->Parameters;

 

   const long ikNumParams = pParams->Count ;

 

   TRACE (L"There are %d params in %s\n",ikNumParams,pszOccName) ;

 

   for (int i = 1 ; i <= ikNumParams ; i++) {

       CComPtr <Parameter> pParam ;

       pParams->get_Item (CComVariant(i),&pParam) ;

 

       VARIANT VarValue ;

       pParam->get_Value (&VarValue) ;

       CComBSTR bstrParamName ;

       pParam->get_Name (&bstrParamName) ;

       TRACE (L"  param %d is called %s and has a value of %.3f= \n",i,bstrParamName,VarValue.dblVal ) ;

   }

 

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