Issue
How to determine the sub-type of Inventor documents? e.g. Whether the document is a sheet metal rather than a regular part document.
Solution
Document Subtypes are primarily intended to classify geometry as belonging to a certain type as far as its shape is concerned. For instance, an Inventor part document could have SheetMetal or Pipe geometry both of which have their own characteristics.
The value of the Document.SubType property refers to a GUID which is a unique identifier for each of the document sub-types. In order to determine the actual sub-types that these GUID’s refer to, the GUID’s have been documented in the file “DocCLSIDs.h” which you will find in like this: “……\Inventor 20xx\SDK\Include\DOCCLSIDs.h”.
This file also includes some #defines, e.g. #define CLSID_InventorPartDocument_RegGUID “{4D29B490-49B2-11D0-93C3-7E0706000000}” which you could use in your program to check for the document sub-types. You should be able to include this .h file if you are using VC++(or include a copy of this file in your project) and then probably check for the document sub-types.
Please see the code section below for VB.NET, VBA and C++ samples. As far as the VBA sample is concerned, the SubType property(string) on the Document object is compared to the GUID which is in the DocCLSIDs.h file, but, for the C++ sample the pre-processor definitions are compared. The following are just code snippets, if you need the complete projects, please take a look at the attachments to this solution.
VB.NET example
Sub GetSubDocumentType()
'access the active document
Dim oDoc As Document = oApp.ActiveDocument
'get the document type
Dim eDocumentType As DocumentTypeEnum = oDoc.DocumentType
Dim sDocumentType As String = "Unknown"
Select Case eDocumentType
Case DocumentTypeEnum.kAssemblyDocumentObject
sDocumentType = "Assembly Document"
Case DocumentTypeEnum.kDesignElementDocumentObject
sDocumentType = "DesignElement Document"
Case DocumentTypeEnum.kDrawingDocumentObject
sDocumentType = "Drawing Document"
Case DocumentTypeEnum.kForeignModelDocumentObject
sDocumentType = "ForeignModel Document"
Case DocumentTypeEnum.kPartDocumentObject
sDocumentType = "Part Document"
Case DocumentTypeEnum.kPresentationDocumentObject
sDocumentType = "Presentation Document"
Case DocumentTypeEnum.kSATFileDocumentObject
sDocumentType = "SATFile Document"
Case DocumentTypeEnum.kUnknownDocumentObject
sDocumentType = "Unknown Document"
End Select
'get the document sub-type
Dim sDocumentSubType As String = oDoc.SubType
Dim sReadableType As String = "Unknown"
'part document sub-types
'part
Select Case sDocumentSubType
Case "{4D29B490-49B2-11D0-93C3-7E0706000000}"
sReadableType = "part"
'sheet metal
Case "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}"
sReadableType = "sheet metal"
'generic proxy
Case "{92055419-B3FA-11D3-A479-00C04F6B9531}"
sReadableType = "generic proxy"
'compatibility proxy
Case "{9C464204-9BAE-11D3-8BAD-0060B0CE6BB4}"
sReadableType = "compatibility proxy"
'catalog proxy
Case "{9C88D3AF-C3EB-11D3-B79E-0060B0F159EF}"
sReadableType = "catalog proxy"
'assembly document sub-types
Case "{E60F81E1-49B3-11D0-93C3-7E0706000000}"
sReadableType = "assembly"
'drawing document sub-types
Case "{BBF9FDF1-52DC-11D0-8C04-0800090BE8EC}"
sReadableType = "drawing"
'design element document sub-types
Case "{62FBB030-24C7-11D3-B78D-0060B0F159EF}"
sReadableType = "design element"
'presentation document sub-types
Case "{76283A80-50DD-11D3-A7E3-00C04F79D7BC}"
sReadableType = "presentation"
End Select
MsgBox("Document Type: " & sDocumentType & vbNewLine & _
"Document SubType: " + sReadableType)
End Sub
VBA Example:
Sub GetSubDocumentType()
'access the active document
Dim oDoc As Document
Set oDoc = ThisApplication.ActiveDocument
'get the document type
Dim eDocumentType As DocumentTypeEnum
eDocumentType = oDoc.DocumentType
Dim sDocumentType As String
Select Case eDocumentType
Case kAssemblyDocumentObject
sDocumentType = "Assembly Document"
Case kDesignElementDocumentObject
sDocumentType = "DesignElement Document"
Case kDrawingDocumentObject
sDocumentType = "Drawing Document"
Case kForeignModelDocumentObject
sDocumentType = "ForeignModel Document"
Case kPartDocumentObject
sDocumentType = "Part Document"
Case kPresentationDocumentObject
sDocumentType = "Presentation Document"
Case kSATFileDocumentObject
sDocumentType = "SATFile Document"
Case kUnknownDocumentObject
sDocumentType = "Unknown Document"
End Select
'get the document sub-type
Dim sDocumentSubType As String
sDocumentSubType = oDoc.SubType
Dim sReadableType As String
'part document sub-types
'part
Select Case sDocumentSubType
Case "{4D29B490-49B2-11D0-93C3-7E0706000000}"
sReadableType = "part"
'sheet metal
Case "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}"
sReadableType = "sheet metal"
'generic proxy
Case "{92055419-B3FA-11D3-A479-00C04F6B9531}"
sReadableType = "generic proxy"
'compatibility proxy
Case "{9C464204-9BAE-11D3-8BAD-0060B0CE6BB4}"
sReadableType = "compatibility proxy"
'catalog proxy
Case "{9C88D3AF-C3EB-11D3-B79E-0060B0F159EF}"
sReadableType = "catalog proxy"
'assembly document sub-types
Case "{E60F81E1-49B3-11D0-93C3-7E0706000000}"
sReadableType = "assembly"
'drawing document sub-types
Case "{BBF9FDF1-52DC-11D0-8C04-0800090BE8EC}"
sReadableType = "drawing"
'design element document sub-types
Case "{62FBB030-24C7-11D3-B78D-0060B0F159EF}"
sReadableType = "design element"
'presentation document sub-types
Case "{76283A80-50DD-11D3-A7E3-00C04F79D7BC}"
sReadableType = "presentation"
End Select
Beep
MsgBox ("Document Type: " & sDocumentType & vbNewLine & _
"Document SubType: " + sReadableType)
End Sub
C++ Example:
static CString GetDocumentSubType()
{
HRESULT Result = NOERROR;
//text box message
CString message;
message.operator = ("A document has not yet been opened using Application");
//***create and access Inventor Application object***
//get the server ClassId from the ProgId
CLSID ApplicationClsid;
Result = ::CLSIDFromProgID(L"Inventor.Application", &ApplicationClsid);
if (FAILED(Result))
return message.operator =("Failed to get the ClassId from the ProgId");
//declare top level Application interface object,Application
CComPtr pAppUnk;
CComPtr pApplication;
//latch on to an existing Inventor session's Application object
Result = ::GetActiveObject(ApplicationClsid, NULL, &pAppUnk);
//if not open create a new Inventor session and get its Application object
if (FAILED(Result)) {
Result = ::CoCreateInstance(ApplicationClsid, NULL, CLSCTX_LOCAL_SERVER, __uuidof(IUnknown), (void**)&pAppUnk);
if (FAILED(Result))
return message.operator =("Failed to get hold of Inventor's Application object");
}
//QueryInterface for the actual Application object
Result = pAppUnk->QueryInterface(__uuidof(Application), (void**)&pApplication);
if (FAILED(Result))
return message.operator =("Failed to get hold of Inventor's Application object");
//if a new Inventor window is created, it is invisible by default, make it visible
Result = pApplication->put_Visible(VARIANT_TRUE);
if (FAILED(Result))
return message.operator =("Failed to make Inventor window visible");
//***open a document using Application object***
//declare Inventor Application document,Document
CComPtr pApplicationDoc;
//open the document
//get the active document
Result = pApplication->get_ActiveDocument(&pApplicationDoc);
if (FAILED(Result) || (!pApplicationDoc))
return message.operator = ("Please open a document in the Inventor session");
//***read information about the document
//get the document type
DocumentTypeEnum DocumentType;
Result = pApplicationDoc->get_DocumentType(&DocumentType);
if (FAILED(Result))
return message.operator = ("Failed to get DocumentType property");
//set the display messages for the text box
char* documenttype;
switch (DocumentType) {
//Assembly
case kAssemblyDocumentObject:
documenttype = "Assembly Document";
break;
//DesignElement
case kDesignElementDocumentObject:
documenttype = "DesignElement Document";
break;
//Drawing
case kDrawingDocumentObject:
documenttype = "Drawing Document";
break;
//ForeignModel
case kForeignModelDocumentObject:
documenttype = "ForeignModel Document";
break;
//Part
case kPartDocumentObject:
documenttype = "Part Document";
break;
//Presentation
case kPresentationDocumentObject:
documenttype = "Presentation Document";
break;
//SATFile
case kSATFileDocumentObject:
documenttype = "SATFile Document";
break;
//Unknown
case kUnknownDocumentObject:
documenttype = "Unknown Document";
break; // Added missing break statement for 'Unknown' case
}
//get the document subtype
CComBSTR docsubtype;
char* readabletype;
Result = pApplicationDoc->get_SubType(&docsubtype);
//part document sub-types
//part document
if (docsubtype.operator == (CLSID_InventorPartDocument_RegGUID))
readabletype = "part";
//sheet metal
if (docsubtype.operator == (CLSID_InventorSheetMetalPart_RegGUID))
readabletype = "sheet metal";
//generic proxy
if (docsubtype.operator == (CLSID_InventorGenericProxyPart_RegGUID))
readabletype = "generic proxy";
//compatibility proxy
if (docsubtype.operator == (CLSID_InventorCompatibilityProxyPart_RegGUID))
readabletype = "compatibility proxy";
//catalog proxy
if (docsubtype.operator == (CLSID_InventorCatalogProxyPart_RegGUID))
readabletype = "catalog proxy";
//assembly document sub-types
if (docsubtype.operator == (CLSID_InventorAssemblyDocument_RegGUID))
readabletype = "assembly";
//drawing document sub-types
if (docsubtype.operator == (CLSID_InventorDrawingDocument_RegGUID))
readabletype = "drawing";
//design element document sub-types
if (docsubtype.operator == (CLSID_InventorDesignElementDocument_RegGUID))
readabletype = "design element";
//presentation document sub-types
if (docsubtype.operator == (CLSID_InventorPresentationDocument_RegGUID))
readabletype = "presentation";
message.Format("Document Type: %s \r\nDocument SubType: %s", documenttype, readabletype);
return message;
}

Leave a Reply