Add in the occurrence of a custom iPart into an assembly

Top  Previous  Next

The most difficult part of adding a custom iPart  into an assembly is understanding how to specify the parameters.

 

The first step is to get hold of the list of occurrences so you can add a new occurrence to the list.

 

Then you create a matrix and a vector to specify the position (and any rotations etc.) of the object.

 

Then you create a list of parameters in column order of the iPart. When you use the iPart Author you'll see the custom parameters in purple. Use that order. These parameters have to be created in a COleSafeArray.

 

Now you are ready to call AddCustomiPartMember with the objects you created in the previous steps.

 

Here is a fragment which assumes you already have an AssemblyComponentDefinition:

 

   CComPtr<ComponentOccurrences> pOccs;

   hRes = pAssemblyCompDef->get_Occurrences(&pOccs);

 

   // This is the name of the iPart factory, from which custom iParts will be created...

   CComBSTR strFactoryFile(L"C:\\TEST\\CustomCylinder.ipt") ;

 

   // Get hold of the transient geometry pointer to create the matrix which says

   // where to place the custom iPart...

   CComPtr<TransientGeometry> pTransGeom = GetTransGeomPtr() ;

   CComPtr<Matrix> pMatrix; // Defaults to 0,0,0 position

   pTransGeom->CreateMatrix(&pMatrix);

   CComPtr<Vector> pVector; // Create a Vector to modify the Matrix

   pTransGeom->CreateVector(2,2,0,&pVector);

   hRes = pMatrix->SetTranslation (pVector,VARIANT_TRUE) ;

 

   // This is the name of the output file, the iPart created from the factory file...

   CComBSTR strFullFileName(L"C:\\CHS_LHS_COLL\\CUSTOMCYL2.ipt") ;

   CComVariant varEmpty ; // Nothing because we are not selecting a row

 

   // We are not selecting a row but we are changing parameters. Here is how

   // we specify those parameters...

#define NUM_PARAMS 2

   BSTR strBSTR[NUM_PARAMS] =

       {

               CString("20 cm").AllocSysString(),

               CString("10 cm").AllocSysString(),

       };

 

   COleSafeArray oleSafeArray;

   oleSafeArray.CreateOneDim(VT_BSTR, NUM_PARAMS, strBSTR);

 

   CComPtr<ComponentOccurrence> pCyl1Occ;

   pOccs->AddCustomiPartMember(strFactoryFile,pMatrix,strFullFileName,varEmpty,oleSafeArray,&pCyl1Occ) ;

 

I've not yet found out how to create the parameter list when not using MFC. COleSafeArray is an MFC object.

 

See also AddCustomiPartMember details and tips.

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