Get the name of a part from the occurrence or the definition

Top  Previous  Next

See also GetOccurenceName

 

First note the difference between DisplayName and PartName:

 

display-vs-part-names

 

If you have the occurrence of a part you can get the display name of it (with its :count part), the filename, like this:

 

    CComPtr<ReferencedFileDescriptor> pRefFileDescA = pOccA->ReferencedFileDescriptor ;

    CComBSTR bstrAName;

    HRESULT hRes = pRefFileDescA->get_DisplayName (&bstrAName) ;

    CString csAName ;

    if (SUCCEEDED(hRes)) { 

        csAName = CString  (bstrAName) ;

    }

 

 

If you have a part component definition:

 

CString GetPartName (CComPtr<PartComponentDefinition>& pPartCompDef)

{

   CString csPartName;

   CComPtr<Document> pDocument;

   HRESULT hRes = pPartCompDef->get_Document((IDispatch**)&pDocument);

 

   if (FAILED(hRes)) {

       ShowCOMError(hRes, L"Could not get part name pDocument");

       return csPartName;

   }

 

   CComBSTR bstrPartName;

   hRes = pDocument->get_DisplayName(&bstrPartName);

 

   if (FAILED(hRes)) {

       ShowCOMError(hRes, L"Could not get part name display name");

       return csPartName;

   }

 

   csPartName = CString  (bstrPartName) ;

 

   return csPartName;

}

 

Note it returns the IPT o IAM extension

 

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