Documents referenced by a 2d view in an IDW

Top  Previous  Next

A (2D) drawing view obviously referenced documents (3D assemblies and 3D parts), how do you get hold of the referenced documents. Here a code fragment to help you do it:


   CComPtr<DrawingView> pThisView = nullptr ;


   // What main document does this view look at? (Here I assume it is an assembly)

   CComPtr<DocumentDescriptor> pDocDesc = nullptr;


   CComQIPtr<AssemblyDocument>pDoc = pDocDesc->ReferencedDocument;


   // Get the definition of the referenced assembly....

   CComPtr<AssemblyComponentDefinition> pAsmCompDef = nullptr;



   // Get the list of components (usually parts) in the assemly...

   CComPtr<ComponentOccurrences> pOccList = nullptr;




   CComQIPtr<PartComponentDefinition> pPartDef = nullptr;

   CComPtr<PartDocument> pOccDoc = nullptr;


   // Loop over all the parts writing out the name of the part...

   for (long o = 1; o <= pOccList->Count; o++) {

       CComPtr<ComponentOccurrence> pOcc = nullptr;

       pOccList->get_Item(o, &pOcc);


       CComPtr<ComponentDefinition> pDef = nullptr ;


       pPartDef = pDef ;



       const CString kcsOccFullFileName(BSTR(pOccDoc->FullFileName));


       pOccDoc = nullptr;


       TRACE L"Found part doc <%s>", kcsOccFullFileName);




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