Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
Maxim-CADman77
1198 Views, 8 Replies

Logical type of Active Inv Doc (if TryCast is a best bet)

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