Counting the number of documents open in Inventor |
Top Previous Next |
Get a pointer to the Inventor application, then use this code:
// Get the list of Documents CComPtr<Documents> pDocs; HRESULT hr = pInvApp->get_Documents(&pDocs); if (FAILED(hr)) { return ReturnAndShowCOMError (hr,L"CreateNewPartDoc, get document list failed\n") ; } const long ikNumDocs = pDocs->GetCount() ; TRACE (L"There are %d documents open in Inventor\n",ikNumDocs) ;
Here is a function which encloses the above code:
size_t GetNumDocummentsOpenInInventor() { CComPtr<Application> pInvApp = theApp.GetInvAppPtr() ; if (pInvApp == nullptr) { return 0 ; }
// Get the list of documents... CComPtr<Documents> pDocs ; HRESULT hRes = pInvApp->get_Documents (&pDocs) ; if (FAILED(hRes) || (pDocs == nullptr)) { ShowCOMError(hRes,L"GNDOII,get_Documents failed "); return 0 ; }
return pDocs->Count ; }
You can loop over the open dopcuments in Inventor like this:
// Get the pointer to the Inventor application... CComPtr<Application> pInvApp = ...
CComPtr<Documents> pDocs ; HRESULT hRes = pInvApp->get_Documents (&pDocs) ; if (FAILED(hRes) || (pDocs == nullptr)) { TRACE (L"RunTest,get_Documents failed "); return ; }
const long ikNumDocs = pDocs->GetCount() ;
TRACE ("There are %d documents open\n",ikNumDocs) ;
for (int iDoc = 1 ; iDoc <= ikNumDocs ; iDoc++) { CComPtr<Document> pDocument; hRes = pDocs->get_Item(iDoc,&pDocument) ; if (FAILED(hRes) || (pDocument == nullptr)) { TRACE (L"Could not get document number %d",iDoc); return ; } TRACE ("Got document %d of type %d %s\n", iDoc, pDocument->DocumentType, GetInventorDocTypeDesc(pDocument->DocumentType)); }
You'll get a listing in the debug window something like this:
Got document 1 of type 12291 Assembly Document Got document 2 of type 12290 Part Document Got document 3 of type 12290 Part Document Got document 4 of type 12290 Part Document Got document 5 of type 12290 Part Document Got document 6 of type 12290 Part Document Got document 7 of type 12290 Part Document Got document 8 of type 12290 Part Document Got document 9 of type 12292 Drawing Document Got document 10 of type 12290 Part Document
|
Text, images and diagrams © 2021 Owen F. Ransen. All rights reserved. (But copy the source code as much as you want!)