Here's a modified version of the SimpleExe sample that's delivered with
Inventor. To determine if a document is visible you need to check and see
if it has any views. This demonstrates that process. (Watch out for line
wrapping.)
static HRESULT GetInventorInformation()
{
HRESULT Result = NOERROR;
TCHAR Str[_MAX_PATH];
CLSID InvAppClsid;
Result = CLSIDFromProgID (L"Inventor.Application", &InvAppClsid);
if (FAILED(Result)) return Result;
CComPtr
pInvAppUnk;
Result = ::GetActiveObject (InvAppClsid, NULL, &pInvAppUnk);
if (FAILED (Result))
_tprintf_s (_T("*** Could not get hold of an active Inventor application
***\n"));
if (FAILED(Result)) return Result;
CComPtr pInvApp;
Result = pInvAppUnk->QueryInterface (__uuidof(Application), (void **)
&pInvApp);
if (FAILED(Result)) return Result;
// Iterate through the open documents to see if they're visible or not.
CComPtr pDocuments;
Result = pInvApp->get_Documents(&pDocuments);
if (FAILED(Result)) return Result;
long docCount;
Result = pDocuments->get_Count(&docCount);
if (FAILED(Result)) return Result;
int i;
for (i=1; i
{
CComPtr pDocument;
Result = pDocuments->get_Item(i, &pDocument);
if (FAILED(Result)) return Result;
// Check to see if it's visible by looking to see if it has any views.
CComPtr pViews;
Result = pDocument->get_Views(&pViews);
if (FAILED(Result)) return Result;
long viewCount;
Result = pViews->get_Count(&viewCount);
VARIANT_BOOL bVisible;
if (viewCount > 0)
bVisible = VARIANT_TRUE;
else
bVisible = VARIANT_FALSE;
if (bVisible == VARIANT_TRUE)
_tcscpy_s (Str, _T("Visible"));
else
_tcscpy_s (Str, _T("Invisible"));
CComBSTR bstrDocName;
Result = pDocument->get_DisplayName(&bstrDocName);
_tprintf_s(_T("%s is %s\n"), bstrDocName, Str);
}
_tscanf_s(_T("Continue: %s"), &Str);
return Result;
}
--
Brian Ekins
Autodesk Inventor API