- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm playing around with iLogic trying to find best way to get logical type of active document.
I mean those logical types:
3D-models
- Generic Part
- Generic Assembly
- Generic Drawing
- iPart Factory
- iPart Member
- iAssy Factory
- iAssy Member
2D-drawings
- Generic Drawing (not based on any 3D-model)
- Exploded View Drawing
- (Single) Part Drawing
- (Single) Assembly Drawing
- Multi-configuration Part Drawing (based on iPart Member or iPart Factory)
- Multi-configuration Assembly Drawing (based on iAssy Member or iAssy Factory)
I 've achieved my goal to about 75%. There are problems with Generic Drawing (object not set to an instance of an object) and both multi-config drawings (I'm a bit confused by depth of object tree and can't find how to get object types for i- factories and members).
My current version of code is:
Dim partDoc As PartDocument = TryCast(ThisDoc.Document, PartDocument) Dim assyDoc As AssemblyDocument = TryCast(ThisDoc.Document, AssemblyDocument) Dim drwDoc As DrawingDocument = TryCast(ThisDoc.Document, DrawingDocument) Dim MsgBody As String If (partDoc IsNot Nothing) Then oCompDef=partDoc.ComponentDefinition If (oCompDef.iPartFactory IsNot Nothing) Then MsgBody="iPart Factory" Else If (oCompDef.iPartMember IsNot Nothing) Then MsgBody="iPart Member" Else MsgBody="Generic Part" End If Else If (assyDoc IsNot Nothing) Then oCompDef=assyDoc.ComponentDefinition If (oCompDef.iAssemblyFactory IsNot Nothing) Then MsgBody="iAssy Factory" Else If (oCompDef.iAssemblyMember IsNot Nothing) Then MsgBody="iAssy Member" Else MsgBody="Generic Assembly" End If Else If (drwDoc IsNot Nothing) Then Dim ModelExt As String = TryCast (IO.Path.GetExtension(ThisDrawing.ModelDocument.FullFileName).ToLower, String) If ModelExt=".ipn" Then MsgBody="Exploded view drawing" Else If ModelExt=".ipt" Then MsgBody="Part drawing" ' If ??? Then MsgBody="Multi-config Part drawing" Else If ModelExt=".iam" Then MsgBody="Assembly drawing" ' If ??? Then MsgBody="Multi-config Assy drawing" Else MsgBody="Generic Drawing" End If Else MsgBody="UnknownDoc" End If MsgBox (MsgBody,,"Type of active doc is:")
Can somebody help me with this, please
Please vote for Inventor-Idea Text Search within Option Names
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Would any of this info help you?
Sub Test()
Dim app As Application
Dim Doc As Document
Dim CompDef As ComponentDefinition
Dim PartType As String
Set app = ThisApplication
Set Doc = app.ActiveDocument
Set CompDef = Doc.ComponentDefinition
iPartFac = CompDef.IsiPartFactory
iPartMem = CompDef.IsiPartMember
Select Case Doc.DocumentType
Case Is = DocumentTypeEnum.kPartDocumentObject
PartType = "Part File"
Case Is = DocumentTypeEnum.kDrawingDocumentObject
PartType = "Drawing File"
'Case Is .... keep going with these
End Select
End SubThose may be easier then what you're doing.
I know you'll have to have some error trapping but that should be a good start.
Mass Override for Each Model State
Custom Glyph Icon for iMates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
This will probably match more to what you had started.
Sub Test()
Dim app As Application
Dim Doc As Document
Dim CompDef As ComponentDefinition
Dim MsgBody As String
Set app = ThisApplication
Set Doc = app.ActiveDocument
Select Case Doc.DocumentType
Case Is = DocumentTypeEnum.kPartDocumentObject
MsgBody = "Part File"
Set CompDef = Doc.ComponentDefinition
If CompDef.IsiPartFactory Then MsgBody = "Multi-config Part Factory"
If CompDef.IsiPartMember Then MsgBody = "Multi-config Part Member"
Case Is = DocumentTypeEnum.kDrawingDocumentObject
MsgBody = "Plain Drawing File"
Dim DocM As Document
Set DocM = Doc.ReferencedDocuments.Item(1)
Set CompDef = DocM.ComponentDefinition
Select Case DocM.DocumentType
Case Is = DocumentTypeEnum.kPartDocumentObject
MsgBody = "Part Drawing File"
If CompDef.IsiPartFactory Then MsgBody = "Multi-config Part drawing Factory"
If CompDef.IsiPartMember Then MsgBody = "Multi-config Part drawing Member"
Case Id = DocumentTypeEnum.kAssemblyDocumentObject
MsgBody = "Assy Drawing File"
If CompDef.IsiPartFactory Then MsgBody = "Multi-config Assy drawing Factory"
If CompDef.IsiPartMember Then MsgBody = "Multi-config Assy drawing Member"
End Select
Case Is = DocumentTypeEnum.kAssemblyDocumentObject
MsgBody = "Assy File"
Set CompDef = Doc.ComponentDefinition
If CompDef.IsiAssemblyFactory Then MsgBody = "Multi-config Assy Factory"
If CompDef.IsiAssemblyMember Then MsgBody = "Multi-config Assy Member"
End Select
MsgBox (MsgBody)
End Sub
Mass Override for Each Model State
Custom Glyph Icon for iMates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Thanks. The only weak place - attempt to execute this on empty (without reference to 3Dmodel) drawing -
Run-time error '5': Invalid procedure call or argument.
How would you recommend to treat such errors?
Please vote for Inventor-Idea Text Search within Option Names
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Sub Test()
Dim app As Application
Dim Doc As Document
Dim CompDef As ComponentDefinition
Dim MsgBody As String
Set app = ThisApplication
Set Doc = app.ActiveDocument
Select Case Doc.DocumentType
Case Is = DocumentTypeEnum.kPartDocumentObject
MsgBody = "Part File"
Set CompDef = Doc.ComponentDefinition
If CompDef.IsiPartFactory Then MsgBody = "Multi-config Part Factory"
If CompDef.IsiPartMember Then MsgBody = "Multi-config Part Member"
Case Is = DocumentTypeEnum.kDrawingDocumentObject
MsgBody = "Plain Drawing File"
Dim DocM As Document
If Doc.ReferencedDocuments.Count > 0 Then
Set DocM = Doc.ReferencedDocuments.Item(1)
Set CompDef = DocM.ComponentDefinition
Select Case DocM.DocumentType
Case Is = DocumentTypeEnum.kPartDocumentObject
MsgBody = "Part Drawing File"
If CompDef.IsiPartFactory Then MsgBody = "Multi-config Part drawing Factory"
If CompDef.IsiPartMember Then MsgBody = "Multi-config Part drawing Member"
Case Id = DocumentTypeEnum.kAssemblyDocumentObject
MsgBody = "Assy Drawing File"
If CompDef.IsiPartFactory Then MsgBody = "Multi-config Assy drawing Factory"
If CompDef.IsiPartMember Then MsgBody = "Multi-config Assy drawing Member"
End Select
End If
Case Is = DocumentTypeEnum.kAssemblyDocumentObject
MsgBody = "Assy File"
Set CompDef = Doc.ComponentDefinition
If CompDef.IsiAssemblyFactory Then MsgBody = "Multi-config Assy Factory"
If CompDef.IsiAssemblyMember Then MsgBody = "Multi-config Assy Member"
End Select
MsgBox (MsgBody)
End Sub
Mass Override for Each Model State
Custom Glyph Icon for iMates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Extensive testing revealed issues with Assy Drawing
Case Is = DocumentTypeEnum.kPartDocumentObject
MsgBody = "Part Drawing File"
If CompDef.IsiPartFactory Then MsgBody = "Multi-config Part drawing Factory"
If CompDef.IsiPartMember Then MsgBody = "Multi-config Part drawing Member"
Case Id = DocumentTypeEnum.kAssemblyDocumentObjectIf replace "Id" with "Is" then "Public member 'IsiPartFactory' on type 'AssemblyComponentDefinition' not found." ![]()
Please vote for Inventor-Idea Text Search within Option Names
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Got it - should be:
Sub Test()
Dim app As Application
Dim Doc As Document
Dim CompDef As ComponentDefinition
Dim MsgBody As String
Set app = ThisApplication
Set Doc = app.ActiveDocument
Select Case Doc.DocumentType
Case DocumentTypeEnum.kPartDocumentObject
MsgBody = "Part File"
Set CompDef = Doc.ComponentDefinition
If CompDef.IsiPartFactory Then MsgBody = "Multi-config Part Factory"
If CompDef.IsiPartMember Then MsgBody = "Multi-config Part Member"
Case DocumentTypeEnum.kDrawingDocumentObject
MsgBody = "Plain Drawing File"
Dim DocM As Document
If Doc.ReferencedDocuments.Count > 0 Then
Set DocM = Doc.ReferencedDocuments.Item(1)
Set CompDef = DocM.ComponentDefinition
Select Case DocM.DocumentType
Case DocumentTypeEnum.kPartDocumentObject
MsgBody = "Part Drawing File"
If CompDef.IsiPartFactory Then MsgBody = "Multi-config Part drawing Factory"
If CompDef.IsiPartMember Then MsgBody = "Multi-config Part drawing Member"
Case DocumentTypeEnum.kAssemblyDocumentObject
MsgBody = "Assy Drawing File"
If CompDef.IsiAssemblyFactory Then MsgBody = "Multi-config Assy drawing Factory"
If CompDef.IsiAssemblyMember Then MsgBody = "Multi-config Assy drawing Member"
End Select
End If
Case DocumentTypeEnum.kAssemblyDocumentObject
MsgBody = "Assy File"
Set CompDef = Doc.ComponentDefinition
If CompDef.IsiAssemblyFactory Then MsgBody = "Multi-config Assy Factory"
If CompDef.IsiAssemblyMember Then MsgBody = "Multi-config Assy Member"
End Select
MsgBox (MsgBody)
End SubAnyway solution is yours.. Thanks!
Please vote for Inventor-Idea Text Search within Option Names
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Oops. I caught it in the assembly section itself but missed it in the drawing/assembly section. Sorry. Thank you for the solution and posting the correct code.
Mass Override for Each Model State
Custom Glyph Icon for iMates