Loop over part occurrences in an assembly

Top  Previous  Next

Here's an example, which also shows the use of _b_str_t and DisplayName and the filename of the part:

 

   CComPtr<ComponentOccurrences> pOccurrences;

   hRes = pAssemblyCompDef->get_Occurrences (&pOccurrences) ;

 

   // Note the i starts at 1, NET counting

   for (int i = 1; i <= pOccurrences->Count; i++) {

       CComPtr<ComponentOccurrence> pThisCompOcc  ;

       hRes = pOccurrences->get_Item(i, &pThisCompOcc);

 

       _bstr_t DisplayName = pThisCompOcc->Get_DisplayName();

       CString csDisplayName = CString (DisplayName.GetBSTR());

 

       CComPtr<DocumentDescriptor> pDocDesc  ;

       pThisCompOcc->get_ReferencedDocumentDescriptor (&pDocDesc) ;

       CComBSTR bstrFullDocName ;

       pDocDesc->get_FullDocumentName (&bstrFullDocName) ;

 

       gLogger.Printf(ekLogMsg, L"Occ <%s> Disp=<%s>", CString(bstrFullDocName), csDisplayName);

   }

 

The DisplayName is what appears in the tree list of the assembly, by the way. The output in the display name also includes the number of the part inserted, after the ":"

 

 

Occurrence <C:\Owen\DirA\Curve_Rame_12\30091328.ipt> Display=<30091328:17>

Occurrence <C:\Owen\DirA\Forcelle_Rame_12_Rigato\30093874.ipt> Display=<30093874:22>

Occurrence <C:\Owen\DirA\Curve_Rame_12\30091327.ipt> Display=<30091327:18>

Occurrence <C:\Owen\DirA\Forcelle_Rame_12_Rigato\30093882.ipt> Display=<30093882:23>

 

 

 

 

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