<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Get TypeName from DocumentType in Inventor Programming Forum</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-forum/get-typename-from-documenttype/m-p/13203616#M3714</link>
    <description>&lt;P&gt;I use:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="visual-basic"&gt;Option Explicit On
Option Strict On
Option Infer Off&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also try to use pure VB code.&lt;/P&gt;&lt;P&gt;This keep intellisense working and no type error when late blinding failed.&lt;/P&gt;</description>
    <pubDate>Tue, 10 Dec 2024 16:54:03 GMT</pubDate>
    <dc:creator>hollypapp65</dc:creator>
    <dc:date>2024-12-10T16:54:03Z</dc:date>
    <item>
      <title>Get TypeName from DocumentType</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/get-typename-from-documenttype/m-p/13203437#M3711</link>
      <description>&lt;P&gt;I like to use the settings "Option Explicit On" and "Option Strict On" in my code.&lt;BR /&gt;This helps me to catch any errors during the design phase.&lt;/P&gt;&lt;P&gt;Unfortunately, this sometimes also costs a lot of extra code (For example, to prevent Late Binding).&lt;/P&gt;&lt;P&gt;I try to avoid creating a Class myself (I know that the Class ThisRule is created at runtime anyway). But this helps to keep using IntelliSense. A Global Module with Shared variables is not possible because of this. Because of this I have to, among other things, pass everything ByVal or ByRef when calling Sub-routines.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I ensure the existence of (1) User Parameters and (2) custom iProperties (create if not existing). Then (3) I provide these Parameters with a specific format (and export settings) and (4) I provide iProperties (if different) with a calculated value, based on certain conditions. In (3) and (4) I walk through all States if FactoryDocument with ModelStates.Count &amp;gt;=1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For this, I have an extensive iLogic rule (multiple subs and functions) for managing User Parameters and (Custom) iProperties. This Rule starts abstract, arranges some general matters (writeability, referencing factory document, etc.) and then executes some more explicit actions based on DocumentType.&lt;BR /&gt;For this I have to perform a type conversion on "oDoc" to AssemblyDocument, PartDocument or DrawingDocument&amp;nbsp;in several places in my code.&lt;BR /&gt;Is it possible to get the TypeName of oDoc.DocumentType and use it as input for CType(oDoc, &amp;lt;here&amp;gt;)?&lt;/P&gt;&lt;P&gt;I want to call a series of subroutines with a "For Each oModelState as ModelState in oDoc.ModelStates". The code for Parts and Assemblies is the same in this respect.&lt;/P&gt;&lt;P&gt;The subroutines themselves further determine how they handle Parts and Assemblies.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Dec 2024 15:22:23 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/get-typename-from-documenttype/m-p/13203437#M3711</guid>
      <dc:creator>PolemEngineering</dc:creator>
      <dc:date>2024-12-10T15:22:23Z</dc:date>
    </item>
    <item>
      <title>Re: Get TypeName from DocumentType</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/get-typename-from-documenttype/m-p/13203486#M3712</link>
      <description>&lt;P&gt;I could use Shared Variables, if:&lt;BR /&gt;- I make sure they are removed when the Rule is finalized&lt;BR /&gt;- I am sure that, when multiple documents trigger the External Rule, they are still processed one by one (and document 2 does not continues with information from document 1).&lt;/P&gt;</description>
      <pubDate>Tue, 10 Dec 2024 15:33:40 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/get-typename-from-documenttype/m-p/13203486#M3712</guid>
      <dc:creator>PolemEngineering</dc:creator>
      <dc:date>2024-12-10T15:33:40Z</dc:date>
    </item>
    <item>
      <title>Re: Get TypeName from DocumentType</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/get-typename-from-documenttype/m-p/13203614#M3713</link>
      <description>&lt;LI-CODE lang="visual-basic"&gt;Dim oTempDoc As Inventor.DrawingDocument
Dim oDoc As Inventor.Document
Dim oDrawDoc As Inventor._DrawingDocument
Dim oPartDoc As Inventor.PartDocument
Dim oAssemDoc As Inventor.AssemblyDocument

oDoc = ThisApplication.ActiveDocument
Select Case oDoc.DocumentType 
Case DocumentTypeEnum.kDrawingDocumentObject
	oDrawDoc = TryCast(oDoc, Inventor._DrawingDocument)
	DrawingUpdate(oDrawDoc)
Case DocumentTypeEnum.kPartDocumentObject
	oPartDoc = TryCast(oDoc, Inventor.PartDocument)
	PartUpdate(oPartDoc)
Case DocumentTypeEnum.kAssemblyDocumentObject
	oAssemDoc = TryCast(oDoc, Inventor.AssemblyDocument)
	AssemUpdate(oAssemDoc)
End Select&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 10 Dec 2024 16:49:58 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/get-typename-from-documenttype/m-p/13203614#M3713</guid>
      <dc:creator>hollypapp65</dc:creator>
      <dc:date>2024-12-10T16:49:58Z</dc:date>
    </item>
    <item>
      <title>Re: Get TypeName from DocumentType</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/get-typename-from-documenttype/m-p/13203616#M3714</link>
      <description>&lt;P&gt;I use:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="visual-basic"&gt;Option Explicit On
Option Strict On
Option Infer Off&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also try to use pure VB code.&lt;/P&gt;&lt;P&gt;This keep intellisense working and no type error when late blinding failed.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Dec 2024 16:54:03 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/get-typename-from-documenttype/m-p/13203616#M3714</guid>
      <dc:creator>hollypapp65</dc:creator>
      <dc:date>2024-12-10T16:54:03Z</dc:date>
    </item>
    <item>
      <title>Re: Get TypeName from DocumentType</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/get-typename-from-documenttype/m-p/13204986#M3715</link>
      <description>&lt;P&gt;Of course, there are many roads that lead to Rome.&lt;/P&gt;&lt;P&gt;It is precisely the specific creation of variables such as oPartDoc, oAsmDoc etc. that makes the code less abstract.&lt;/P&gt;&lt;P&gt;I have now solved it by giving an extra argument ByRef to my GetFactoryDocument function. This is already working with the ModelStates object. Then it can also assign a reference to the ModelStates object.&lt;/P&gt;&lt;LI-CODE lang="visual-basic"&gt;Function GetFactoryDocument(ByRef oDoc As Document, ByRef oModelStates As ModelStates) As Document

	If (oDoc Is Nothing) Then Return Nothing

	Dim oDocType As DocumentTypeEnum = oDoc.DocumentType

	If Not ((oDocType = DocumentTypeEnum.kPartDocumentObject) Or (oDocType = DocumentTypeEnum.kAssemblyDocumentObject)) Then
		Return oDoc
	End If

	If (oDocType = DocumentTypeEnum.kPartDocumentObject) Then
		Dim oDef As PartComponentDefinition = TryCast(oDoc, PartDocument).ComponentDefinition
		oModelStates = oDef.ModelStates
		If (oDef.IsModelStateMember) Then
			Return oDef.FactoryDocument
		ElseIf (oDef.IsModelStateFactory) Then
			Return oDoc
		End If
	End If
	
	If (oDocType = DocumentTypeEnum.kAssemblyDocumentObject) Then
		Dim oDef As AssemblyComponentDefinition = TryCast(oDoc, AssemblyDocument).ComponentDefinition
		oModelStates = oDef.ModelStates
		If (oDef.IsModelStateMember) Then
			Return oDef.FactoryDocument
		ElseIf (oDef.IsModelStateFactory) Then
			Return oDoc
		End If
	End If
	'senseless
	Return oDoc
End Function&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 11 Dec 2024 09:58:24 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/get-typename-from-documenttype/m-p/13204986#M3715</guid>
      <dc:creator>PolemEngineering</dc:creator>
      <dc:date>2024-12-11T09:58:24Z</dc:date>
    </item>
    <item>
      <title>Re: Get TypeName from DocumentType</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/get-typename-from-documenttype/m-p/13205803#M3716</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/552412"&gt;@PolemEngineering&lt;/a&gt;.&amp;nbsp; When it comes to checking document type in my codes, I have mostly switched over from using the &lt;A href="https://help.autodesk.com/view/INVNTOR/2024/ENU/?guid=Document_DocumentType" target="_blank" rel="noopener"&gt;Document.DocumentType&lt;/A&gt; property, and the &lt;A href="https://help.autodesk.com/view/INVNTOR/2024/ENU/?guid=DocumentTypeEnum" target="_blank" rel="noopener"&gt;DocumentTypeEnum&lt;/A&gt; Enum, to using the &lt;A href="https://learn.microsoft.com/en-us/dotnet/visual-basic/language-reference/operators/typeof-operator" target="_blank" rel="noopener"&gt;TypeOf Operator&lt;/A&gt;.&amp;nbsp; It seems to process faster, looks easier to read, and often takes a little less code, so typing it that way is also a bit faster.&amp;nbsp; Since you are already using &lt;A href="https://learn.microsoft.com/en-us/dotnet/visual-basic/language-reference/operators/trycast-operator" target="_blank" rel="noopener"&gt;TryCast Operator&lt;/A&gt;, which requires the a 'type name' (not a String), using the 'TypeOf' operator would be a very natural and logical adaptation to go along with it.&amp;nbsp; There are obviously more variations within the DocumentTypeEnum than there are 'type names' to check against with the 'TypeOf' operator, but 99% of the time I'm only checking for those 3 main types (drawing, part, assembly) anyways.&amp;nbsp; Sometimes, depending on the situation, I also like to just create my own set of Boolean type variables, which have their values set from those checks, as seen in my examples below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I actually did some local testing using the &lt;A href="https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.stopwatch" target="_blank" rel="noopener"&gt;System.Diagnostics.StopWatch&lt;/A&gt;, and found that the 'TypeOf' checks processed 2 to 3 times faster than the DocumentTypeEnum checks.&amp;nbsp; Below are two extremely basic iLogic rules you can test this theory with, as I did.&lt;/P&gt;
&lt;P&gt;TypeOf checks test&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;Dim oDoc As Inventor.Document = ThisDoc.Document
Dim bIsDrawing, bIsPart, bIsAssembly As Boolean
Dim oSW As New System.Diagnostics.Stopwatch()
oSW.Start()
bIsDrawing = (TypeOf oDoc Is DrawingDocument)
bIsPart = (TypeOf oDoc Is PartDocument)
bIsAssembly = (TypeOf oDoc Is AssemblyDocument)
oSW.Stop()
Logger.Info("TypeOf Test Elapsed Ticks = " &amp;amp; oSW.ElapsedTicks.ToString)
oSW.Reset()&lt;/LI-CODE&gt;
&lt;P&gt;DocumentTypeEnum checks test&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;Dim oDoc As Inventor.Document = ThisDoc.Document
Dim bIsDrawing, bIsPart, bIsAssembly As Boolean
Dim oSW As New System.Diagnostics.Stopwatch()
oSW.Start()
bIsDrawing = (oDoc.DocumentType = DocumentTypeEnum.kDrawingDocumentObject)
bIsPart = (oDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject)
bIsAssembly = (oDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject)
oSW.Stop()
Logger.Info("DocumentTypeEnum Test Elapsed Ticks = " &amp;amp; oSW.ElapsedTicks.ToString)
oSW.Reset()&lt;/LI-CODE&gt;
&lt;P&gt;If this solved your problem, or answered your question, please click &lt;SPAN&gt;&lt;STRONG&gt; ACCEPT SOLUTION &lt;/STRONG&gt;&lt;/SPAN&gt;.&lt;BR /&gt;Or, if this helped you, please click (LIKE or KUDOS) &lt;span class="lia-unicode-emoji" title=":thumbs_up:"&gt;👍&lt;/span&gt;.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Dec 2024 17:15:28 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/get-typename-from-documenttype/m-p/13205803#M3716</guid>
      <dc:creator>WCrihfield</dc:creator>
      <dc:date>2024-12-11T17:15:28Z</dc:date>
    </item>
    <item>
      <title>Re: Get TypeName from DocumentType</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/get-typename-from-documenttype/m-p/13247036#M3717</link>
      <description>&lt;P&gt;Wow, I didn't know it made that much of a difference. I'm going to make this habit my own.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jan 2025 09:51:50 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/get-typename-from-documenttype/m-p/13247036#M3717</guid>
      <dc:creator>PolemEngineering</dc:creator>
      <dc:date>2025-01-07T09:51:50Z</dc:date>
    </item>
    <item>
      <title>Re: Get TypeName from DocumentType</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/get-typename-from-documenttype/m-p/13247343#M3718</link>
      <description>&lt;P&gt;If taking the next logical step, and checking DocumentSubType, there are a couple other tips that you may find useful.&lt;/P&gt;
&lt;P&gt;Most of us who have been writing code to automate Inventor for a while have come across the following common properties of the Document object, and attempted to use them.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://help.autodesk.com/view/INVNTOR/2024/ENU/?guid=Document_DocumentSubType" target="_blank" rel="noopener"&gt;Document.DocumentSubType&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://help.autodesk.com/view/INVNTOR/2024/ENU/?guid=Document_SubType" target="_blank" rel="noopener"&gt;Document.SubType&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That first one 'DocumentSubType' appears to now be 'retired', because we can no longer find any further information about how to check its value within the online help documentation, and the links to the value type it returns are now broken.&amp;nbsp; However, it seems as though Autodesk has chosen to continue supporting its functionality in the background, to keep from 'breaking' the functionality of 'legacy' solutions, for now.&amp;nbsp; It claims to return a value that is DocumentSubType Type (not a String or Enum), and when we look older code examples using it, they use it like this [Document.DocumentSubType.DocumentSubTypeID = ], which indicates that value Type was an object that had a property named 'DocumentSubTypeID, which had a String type value, which was one of those long GUID type, unreadable pattern of letters, numbers, &amp;amp; symbols.&lt;/P&gt;
&lt;P&gt;The second one 'Document.SubType' actually returns the same value as 'Document.DocumentSubType.DocumentSubTypeID' did, and does so with far less code or complication.&lt;/P&gt;
&lt;P&gt;However, both of them leave us with a value we can not directly read, or understand clearly.&lt;/P&gt;
&lt;P&gt;And, there is yet another way to get that same value from a Document, through its standard iProperties, in its third PropertySet named 'Design Tracking Properties' (aka 'Project'), and its property at index 16, named 'Document SubType'.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, if you want a value that you can actually read, and understand, we can use the very next iProperty in that same set, named 'Document SubType Name' (index 17).&amp;nbsp; If it is a regular part, it will return "Modeling" (for some reason), if a sheet metal part, it will contain "Sheet Metal" text, if regular assembly, it will contain "Assembly" text, if a weldment type assembly, it will contain "Weldment" text, and so on.&amp;nbsp; This same exact value can be seen within the standard iProperties dialog, on the Project tab, beside the label "File Subtype:" in every document.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The last year or two, I have mostly switched from checking SubType using any of the above mentioned ways, to using the 'TypeOf' operator on the ComponentDefinition object directly, instead.&amp;nbsp; It seems to require less code, and is equally easy to read and understand (at least for me).&amp;nbsp; This is because pretty much every SubType has a unique type of &lt;A href="https://help.autodesk.com/view/INVNTOR/2024/ENU/?guid=GUID-ComponentDefinition" target="_blank" rel="noopener"&gt;ComponentDefinition&lt;/A&gt; to match it, and then some.&amp;nbsp; ComponentDefinition is a base type, which has several other, more specific types derived from it, for special purposes/uses.&amp;nbsp; And some of those sub types even have other more specific sub types derived from them also.&amp;nbsp; At this point in my codes, I am usually about to declare a variable for the ComponentDefinition anyways, which usually requires me typing that TypeName anyways, so this is another relatively efficient and logical way to check it.&lt;/P&gt;
&lt;P&gt;Below is a simple iLogic rule which extracts that same SubTypeID value from the Document object in all 3 ways that I know of, plus shows the 'readable' way I mentioned, but does not show the 'TypeOf' check on the ComponentDefinition, because it does not fit this situation very well.&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;Dim oDoc As Inventor.Document = ThisDoc.Document
Dim sSubType_ID_1 As String = oDoc.DocumentSubType.DocumentSubTypeID
Dim sSubType_ID_2 As String = oDoc.SubType
Dim sSubType_ID_3 As String = oDoc.PropertySets.Item(3).Item(16).Value
Dim sSubTypeName As String = oDoc.PropertySets.Item(3).Item(17).Value
MessageBox.Show("Document SubType Info:" &amp;amp; vbCrLf &amp;amp; _
"Document.DocumentSubType.DocumentSubTypeID = " &amp;amp; sSubType_ID_1 &amp;amp; vbCrLf &amp;amp; _
"Document.SubType = " &amp;amp; sSubType_ID_2 &amp;amp; vbCrLf &amp;amp; _
"'Document SubType' iProperty Value = " &amp;amp; sSubType_ID_3 &amp;amp; vbCrLf &amp;amp; _
"'Document SubType Name' iProperty Value = " &amp;amp; sSubTypeName, _
"This Document's SubType Info", MessageBoxButtons.OK, MessageBoxIcon.Information)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jan 2025 13:18:19 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/get-typename-from-documenttype/m-p/13247343#M3718</guid>
      <dc:creator>WCrihfield</dc:creator>
      <dc:date>2025-01-07T13:18:19Z</dc:date>
    </item>
    <item>
      <title>Re: Get TypeName from DocumentType</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/get-typename-from-documenttype/m-p/13247542#M3719</link>
      <description>&lt;P&gt;I was wondering about that too. How do you get the TypeOf variables? Logger.Info(TypeName(ThisDoc.Document)) after using it a few times it suddenly gives _DocumentClass.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For DocumentSubType I now use a standard piece of code.&lt;/P&gt;&lt;LI-CODE lang="visual-basic"&gt;Sub Main
...
	If Not SharedVariable.Exists("DocSubType") Then
		Dim ReadableDocSubType As Inventor.NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap()
		SharedVariable.Value("DocSubType") = ReadableDocSubType
		Call AddDocSubTypes(ReadableDocSubType)
	End If
...
End Sub&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="visual-basic"&gt;Sub AddDocSubTypes(ByRef ReadableDocSubType As Inventor.NameValueMap)
	'[ Populate the ReadableDocSubType NameValueMap for easy translation later on...
	ReadableDocSubType.Add("{E60F81E1-49B3-11D0-93C3-7E0706000000}", "Assembly")
	ReadableDocSubType.Add("{BBF9FDF1-52DC-11D0-8C04-0800090BE8EC}", "Drawing")
	ReadableDocSubType.Add("{4D29B490-49B2-11D0-93C3-7E0706000000}", "Part")
	ReadableDocSubType.Add("{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}", "Sheet Metal Part")
	ReadableDocSubType.Add("{28EC8354-9024-440F-A8A2-0E0E55D635B0}", "Weldment")
	']
End Sub&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jan 2025 14:45:17 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/get-typename-from-documenttype/m-p/13247542#M3719</guid>
      <dc:creator>PolemEngineering</dc:creator>
      <dc:date>2025-01-07T14:45:17Z</dc:date>
    </item>
    <item>
      <title>Re: Get TypeName from DocumentType</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/get-typename-from-documenttype/m-p/13247720#M3720</link>
      <description>&lt;P&gt;That's not a bad idea.&amp;nbsp; I also had the thought to create my own DocumentSubTypeEnum within an external rule, so I could reference it with 'AddVbFile' from other rules, but I don't recall if I ever finished that thought / idea, to be honest, because I am certainly not using it right now.&lt;/P&gt;
&lt;P&gt;Below is a link to my Inventor Ideas post where I am asking Autodesk to add a&amp;nbsp;DocumentSubTypeEnum, or something similar, to make that step easier.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://forums.autodesk.com/t5/inventor-ideas/create-enum-for-documentsubtype-amp-or-document-subtype/idi-p/9402300" target="_blank" rel="noopener"&gt;https://forums.autodesk.com/t5/inventor-ideas/create-enum-for-documentsubtype-amp-or-document-subtype/idi-p/9402300&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Checking TypeOf ComponentDefinition is not universal way of checking document sub type, but just another tool to keep in the tool belt.&amp;nbsp; I have found it very useful in some situations, but it might not be ideal for 100% of situations.&amp;nbsp; For instance drawings do not have one, and there are some types of ComponentDefinition that do not have a Document associated with them, even if they do have that Property named Document.&amp;nbsp; Below is just a generic sample code I just threw together, because I usually just use a single line in various rules and methods, in various places.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;Dim oDoc As Inventor.Document = ThisDoc.Document
Dim oCD As ComponentDefinition = Nothing
Try : oCD = oDoc.ComponentDefinition : Catch : End Try
Dim bIsDrawing, bIsPart, bIsSheetMetal, bIsFlatPattern, bIsAssembly, bIsWeldment, bIsWelds, bIsVirtual As Boolean

'I do not know of any sub types of drawings, plus they do not have a ComponentDefinition
bIsDrawing = (TypeOf oDoc Is DrawingDocument)
'next one may be true for both regular parts and sheet metal, since sheet metal is derived from part
bIsPart = (oCD IsNot Nothing) AndAlso (TypeOf oCD Is PartComponentDefinition)
'this one is more specific
bIsSheetMetal = (oCD IsNot Nothing) AndAlso (TypeOf oCD Is SheetMetalComponentDefinition)
'this is similar, but not derived from sheet metal definition type
bIsFlatPattern = (oCD IsNot Nothing) AndAlso (TypeOf oCD Is FlatPattern)
'this one may be true for regular assembly and weldment, because weldment derived from assembly
bIsAssembly = (oCD IsNot Nothing) AndAlso (TypeOf oCD Is AssemblyComponentDefinition)
'this one is more specific
bIsWeldment = (oCD IsNot Nothing) AndAlso (TypeOf oCD Is WeldmentComponentDefinition)
'this is not derived from weldment type, and is just the welds in a weldment
bIsWelds = (oCD IsNot Nothing) AndAlso (TypeOf oCD Is WeldsComponentDefinition)
'no actual document, just for adding useful rows into BOM
bIsVirtual = (oCD IsNot Nothing) AndAlso (TypeOf oCD Is VirtualComponentDefinition)

MsgBox( _
"IsDrawing = " &amp;amp; bIsDrawing &amp;amp; vbCrLf &amp;amp; _
"IsPart = " &amp;amp; bIsPart &amp;amp; vbCrLf &amp;amp; _
"IsSheetMetal = " &amp;amp; bIsSheetMetal &amp;amp; vbCrLf &amp;amp; _
"IsFlatPattern = " &amp;amp; bIsFlatPattern &amp;amp; vbCrLf &amp;amp; _
"IsDrawing = " &amp;amp; bIsDrawing &amp;amp; vbCrLf &amp;amp; _
"IsAssembly = " &amp;amp; bIsAssembly &amp;amp; vbCrLf &amp;amp; _
"IsWeldment = " &amp;amp; bIsWeldment &amp;amp; vbCrLf &amp;amp; _
"IsWelds = " &amp;amp; bIsWelds &amp;amp; vbCrLf &amp;amp; _
"IsVirtual = " &amp;amp; bIsVirtual)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jan 2025 16:05:34 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/get-typename-from-documenttype/m-p/13247720#M3720</guid>
      <dc:creator>WCrihfield</dc:creator>
      <dc:date>2025-01-07T16:05:34Z</dc:date>
    </item>
  </channel>
</rss>

