Create a rectangular pattern of parts programatically |
Top Previous Next |
Here is an example. Remember that occurrences are "links to parts" inside an assembly:
bool CreateYArrayOfParts (CComPtr<ComponentOccurrences> pOccurrencesList, // The occurrences in the assembly CComPtr<AssemblyComponentDefinition> pCctsAssemblyCompDef, // def of the assembly CComPtr<ComponentOccurrence> pObjOcc, const double kDeltaYMm, const UINT ikCount) { CComPtr<OccurrencePatterns> pOccPatterns ; pOccPatterns = pCctsAssemblyCompDef->GetOccurrencePatterns(); if (pOccPatterns == nullptr) { gLogger.Printf(ekErrMsg, "GetOccurrencePatterns failed"); return false; }
CComPtr<TransientObjects> pTransientObjects = GetTransientObjectsPtr() ;
CComVariant varObjEnumerator; CComPtr<ObjectCollection> pObjectCollection; HRESULT hRes = pTransientObjects->CreateObjectCollection(varObjEnumerator, &pObjectCollection); if (FAILED(hRes)) { gLogger.Printf(ekErrMsg, "CreateObjectCollection failed"); return false; }
// Add the part which is the basis to the pattern... hRes = pObjectCollection->Add (pObjOcc) ; if (FAILED(hRes)) { gLogger.Printf(ekErrMsg, "Add to ObjectCollection failed"); return false; }
// Get hold of the y axis... CComPtr<WorkAxis> pYWorkAxis ; GetAsmWorkAxisByName (pYWorkAxis,L"Y Axis",pCctsAssemblyCompDef) ; if (FAILED(hRes)) { gLogger.Printf(ekErrMsg, "Could not get assembly y axis"); return false; }
pOccPatterns->AddRectangularPattern(pObjectCollection, _variant_t((IDispatch *)pYWorkAxis), VARIANT_FALSE, CComVariant(kDeltaYMm/10.0), //ColumnOffset As Variant, CComVariant(ikCount), // ColumnCount As Variant, CComVariant(), // [RowEntity] As Variant, VARIANT_TRUE, // [RowEntityNaturalDirection] As Boolean, CComVariant(0.0),// [RowOffset] As Variant, CComVariant(1)); // [RowCount] As Variant)
return (hRes == S_OK) ; }
You could make it more general.
See also suppression of occurrences in a pattern.
|
Text, images and diagrams © 2021 Owen F. Ransen. All rights reserved. (But copy the source code as much as you want!)