Create an ObjectCollection of parts in an assembly |
Top Previous Next |
You won't have all the functions here, you'll have to adapt it, but you get the idea:
CComPtr<ObjectCollection> CreateCollectionOfCctObjects(CComPtr<AssemblyComponentDefinition> pAssemblyCompDef, const CctTypeFlags_t ikObjectsToCollect) { // Make an ObjectCollection of all object types specified... CComPtr<TransientObjects> pTransObjs = GetTransientObjectsPtr() ;
CComPtr<ObjectCollection> pObjCollection = nullptr ; HRESULT hRes = pTransObjs->CreateObjectCollection (gkvarEmpty,&pObjCollection) ; if (FAILED(hRes)) { gLogger.Printf (ekErrMsg,L"CCOCO, CreateObjectCollection failed.") ; return nullptr ; }
// Get ALL the occurrences in the assembly... CComPtr<ComponentOccurrences> pOccurrences = nullptr; hRes = pAssemblyCompDef->get_Occurrences (&pOccurrences) ; if (FAILED(hRes)) { gLogger.Printf (ekErrMsg,L"CCOCO, get_Occurrences failed.") ; return nullptr ; }
// Collect together only the occurrences we are interested in... for (int i = 1; i <= pOccurrences->Count; i++) { CComPtr<ComponentOccurrence> pThisCompOcc = nullptr ; hRes = pOccurrences->get_Item(i, &pThisCompOcc);
_bstr_t DisplayName = pThisCompOcc->Get_DisplayName(); CString kcsDisplayName = CString (DisplayName.GetBSTR());
const CString kcsSapCode = kcsDisplayName.Left(NUM_SAP_CHARS);
const bool kbObjToActOn = SapCodeIsA (kcsSapCode, ikObjectsToCollect) ; if (kbObjToActOn) { pObjCollection->Add(pThisCompOcc); } }
return pObjCollection; }
Can be used to create an ObjectCollection of ParticipatingOccurrences.
|
Text, images and diagrams © 2021 Owen F. Ransen. All rights reserved. (But copy the source code as much as you want!)