While you were doing that in VB, for which many thanks, I wrote this in C++:
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 = theApp.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) ;
...so our readers willl have two examples! 🙂