List iMates in an assembly

Top  Previous  Next

Here's something which will list iMates in an assembly:


   CComPtr<AssemblyComponentDefinition> pAsmCompDef;

   CComPtr<AssemblyDocument> pAsmDoc;

   const CString kcsFullAsmFileName(L"C:\\docs\TestAssembly.Iam") ;


   const bool kbOpenedOk = OpenAssembly (pAsmCompDef,pAsmDoc,kcsFullAsmFileName) ;

   if (!kbOpenedOk) {

       TRACE("Failed to open");




   CComPtr<iMateDefinitions> piMateDefinitions = nullptr ;

   HRESULT hRes = pAsmCompDef->get_iMateDefinitions(&piMateDefinitions);

   if (FAILED(hRes)) {

       TRACE("Failed to get imate definitions");




   TRACE ("There are %d imate definitions\n",piMateDefinitions->GetCount());


   for (int i = 1; i <= piMateDefinitions->GetCount(); i++) {

       CComPtr<iMateDefinition> piMateDef;

       piMateDefinitions->get_Item(i, &piMateDef);


       _bstr_t bstrName =  piMateDef->GetName();

       CString csName1((wchar_t*)bstrName);


       CComPtr<iMateDefinition> piMateDef2;



       TRACE(L"%d %s\n", i, csName1);


       if (piMateDef2 != nullptr) {

           bstrName = piMateDef2->GetName();

           CString csName2((wchar_t*)bstrName);

           TRACE(L"   Referenced entity name = %s\n",csName2);



       CComPtr<ReferenceComponent> pRefComp;


       if (pRefComp != nullptr) {

           TRACE (L"   Refernced component = %s\n",pRefComp->Name) ;



       const ObjectTypeEnum eObjType = piMateDef->GetType();


       TRACE(L"  Obj type is %d <%s>\n", eObjType, GetObjTypeDesc(eObjType));




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