iLogic to hide plans (recursive)

iLogic to hide plans (recursive)

amarcoc
Advocate Advocate
1,241 Views
15 Replies
Message 1 of 16

iLogic to hide plans (recursive)

amarcoc
Advocate
Advocate

Hi

 

I have a iLogic I made to hide all plans in current assembly, or current part.

 

I want to be able to run it in a assembly, and run it in all subassemblies and parts.

 

I want to hide all plans.

 

What should I change to be able to run it recursively?

 

Thanks in advance!

 

Sub Main ()
	Select Case ThisApplication.ActiveDocument.DocumentType
		Case kPartDocumentObject 'Part = kAssemblyDocumentObject = 12290
			For Each oWorkPlane In ThisDoc.Document.ComponentDefinition.WorkPlanes
				Select Case oWorkPlane.Name
					Case "YZ Plane - RIGHT", "XZ Plane - TOP", "XY Plane - FRONT"
					Case "YZ Plane"
						oWorkPlane.Name = "YZ Plane - RIGHT"
					Case "XZ Plane"
						oWorkPlane.Name = "XZ Plane - TOP"
					Case "XY Plane"
						oWorkPlane.Name = "XY Plane - FRONT"
					Case Else
						'MessageBox.Show("Planos não encontrados", "Planos")
				End Select
				oWorkPlane.Visible = False
			Next
		Case kAssemblyDocumentObject 'Assembly = kAssemblyDocumentObject = 12291
			Dim oAsmDoc As AssemblyDocument
			oAsmDoc = ThisApplication.ActiveDocument
			For Each oWorkPlane In oAsmDoc.ComponentDefinition.WorkPlanes
				Select Case oWorkPlane.Name 
					Case "YZ Plane - RIGHT", "XZ Plane - TOP", "XY Plane - FRONT"
					Case "YZ Plane"
						oWorkPlane.Name = "YZ Plane - RIGHT"
					Case "XZ Plane"
						oWorkPlane.Name = "XZ Plane - TOP"
					Case "XY Plane"
						oWorkPlane.Name = "XY Plane - FRONT"
					Case Else
						'MessageBox.Show("Planos não encontrados", "Planos")
				End Select
				oWorkPlane.Visible = False
				oWorkPlane.AutoResize = True
			Next
		Case kDrawingDocumentObject 'Drawing = kDrawingDocumentObject = 12292
	End Select
End Sub

 

0 Likes
Accepted solutions (1)
1,242 Views
15 Replies
Replies (15)
Message 2 of 16

chandra.shekar.g
Autodesk Support
Autodesk Support
Accepted solution

Hi @amarcoc,

 

Try the following iLogic code.

 

Sub Main ()	
	Select Case ThisApplication.ActiveDocument.DocumentType
		Case kPartDocumentObject 'Part = kAssemblyDocumentObject = 12290
			Dim oPartDoc as PartDocument
			oPartDoc = ThisApplication.ActiveDocument
			Planes_Visibilty(oPartDoc.ComponentDefinition)
		Case kAssemblyDocumentObject 'Assembly = kAssemblyDocumentObject = 12291
			Dim oAsmDoc As AssemblyDocument
			oAsmDoc = ThisApplication.ActiveDocument			
			Planes_Visibilty(oAsmDoc.ComponentDefinition)
			Dim oDoc As Document
			For Each oDoc In oAsmDoc.AllReferencedDocuments
				Planes_Visibilty(oDoc.ComponentDefinition)
			Next
		Case kDrawingDocumentObject 'Drawing = kDrawingDocumentObject = 12292
	End Select
End Sub

Sub Planes_Visibilty (ByVal oDef As ComponentDefinition)

	For Each oWorkPlane In oDef.WorkPlanes	

		Select Case oWorkPlane.Name
			Case "YZ Plane - RIGHT", "XZ Plane - TOP", "XY Plane - FRONT"
			Case "YZ Plane"
				oWorkPlane.Name = "YZ Plane - RIGHT"
			Case "XZ Plane"
				oWorkPlane.Name = "XZ Plane - TOP"
			Case "XY Plane"
				oWorkPlane.Name = "XY Plane - FRONT"
			Case Else
				'MessageBox.Show("Planos não encontrados", "Planos")
		End Select
		oWorkPlane.Visible = False
	Next
	
End Sub

Please feel free to contact if there is any doubt.

 

If solves problem, click on "Accept as solution" / give a "Kudo".

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



Message 3 of 16

amarcoc
Advocate
Advocate

Worked perfect, first time. And the code is cleaner.

 

Thanks!

0 Likes
Message 4 of 16

amarcoc
Advocate
Advocate

Hi Chandra

 

I have some assemblies that generate an error.

 

Some do work. What could be the problem?

 

Here is the error:

 

Error in rule: 06 - Recursive HidePlans, in document: 04004.1.002.iam

Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))

More info...

System.Runtime.InteropServices.COMException (0x80004005): Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))
   at Microsoft.VisualBasic.CompilerServices.LateBinding.InternalLateSet(Object o, Type& objType, String name, Object[] args, String[] paramnames, Boolean OptimisticSet, CallType UseCallType)
   at Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateSet(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean OptimisticSet, Boolean RValueBase, CallType CallType)
   at LmiRuleScript.Planes_Visibilty(ComponentDefinition oDef)
   at LmiRuleScript.Main()
   at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
   at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)
0 Likes
Message 5 of 16

chandra.shekar.g
Autodesk Support
Autodesk Support

Hi @amarcoc,

 

Can you please provide non confidential file which is having problem?

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 6 of 16

amarcoc
Advocate
Advocate

Hi.

 

Thank you for the reply.

 

In attachment you have a simple test. That generates error with the code you provided.

 

I noticed the problem seems to happen in iParts or iAssemblies. Not sure.

 

 

0 Likes
Message 7 of 16

chandra.shekar.g
Autodesk Support
Autodesk Support

Hi @amarcoc,

 

Yes, you are right!!! If assembly contains iPart or iAssembly, code does not work.

 

Can you please provide non confidential file of iAssembly to test?

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 8 of 16

amarcoc
Advocate
Advocate

It was in my previous post. I attached a sample before.

 

If nothing else works, I'm OK if the ilogic checks filetype first, and just ignores ipart and iassembly.

 

Thanks.

0 Likes
Message 9 of 16

amarcoc
Advocate
Advocate

Hi Chandra. How can I just ignore iPart and iAssembly? 

0 Likes
Message 10 of 16

chandra.shekar.g
Autodesk Support
Autodesk Support

Hi @amarcoc,

 

iPart or iAssembly has limitation to access workPlanes. But referenced documents of iPart or iAssembly are accessible and can be renamed.

 

Try the following modified iLogic code.

 

Sub Main ()	
	Select Case ThisApplication.ActiveDocument.DocumentType
		Case kPartDocumentObject 'Part = kAssemblyDocumentObject = 12290
			Dim oPartDoc as PartDocument
			oPartDoc = ThisApplication.ActiveDocument
			Planes_Visibilty(oPartDoc.ComponentDefinition)
		Case kAssemblyDocumentObject 'Assembly = kAssemblyDocumentObject = 12291
			Dim oAsmDoc As AssemblyDocument
			oAsmDoc = ThisApplication.ActiveDocument			
			Planes_Visibilty(oAsmDoc.ComponentDefinition)
			Dim oDoc As Document
			For Each oDoc In oAsmDoc.AllReferencedDocuments
				If oDoc.ComponentDefinition.IsiPartMember = True Then
					Dim oPart As iPartMember
					oPart = oDoc.ComponentDefinition.iPartMember
					oDoc = opart.ReferencedDocumentDescriptor.ReferencedDocument
					Planes_Visibilty(oDoc.ComponentDefinition)
				Else
					Planes_Visibilty(oDoc.ComponentDefinition)
				End If
			Next
		Case kDrawingDocumentObject 'Drawing = kDrawingDocumentObject = 12292
	End Select
End Sub

Sub Planes_Visibilty (ByVal oDef As ComponentDefinition)

	For Each oWorkPlane In oDef.WorkPlanes	

		Select Case oWorkPlane.Name
			Case "YZ Plane - RIGHT", "XZ Plane - TOP", "XY Plane - FRONT"
			Case "YZ Plane"
				oWorkPlane.Name = "YZ Plane - RIGHT"
			Case "XZ Plane"
				oWorkPlane.Name = "XZ Plane - TOP"
			Case "XY Plane"
				oWorkPlane.Name = "XY Plane - FRONT"
			Case Else
				'MessageBox.Show("Planos não encontrados", "Planos")
		End Select
		oWorkPlane.Visible = False
	Next
	
End Sub

 

Please feel free to contact if there is any doubt.

 

If solves problem, click on "Accept as solution" / give a "Kudo".

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 11 of 16

amarcoc
Advocate
Advocate

Thank you for the reply.

 

I get this error:

 

 

Error in rule: 06 - Recursive HidePlans, in document: 04004.1.008.iam

Não foi localizado o membro público 'IsiPartMember' no tipo 'AssemblyComponentDefinition'.

 

More info...

 

System.MissingMemberException: Não foi localizado o membro público 'IsiPartMember' no tipo 'AssemblyComponentDefinition'.
   at Microsoft.VisualBasic.CompilerServices.LateBinding.LateGet(Object o, Type objType, String name, Object[] args, String[] paramnames, Boolean[] CopyBack)
   at Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateGet(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack)
   at LmiRuleScript.Main()
   at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
   at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

 

Is there a way to just ignore iPart and iAssembly?

0 Likes
Message 12 of 16

chandra.shekar.g
Autodesk Support
Autodesk Support

Hi @amarcoc,

 

Try the following iLogic code which ignores iPart and iAssembly.

 

Sub Main ()	
	Select Case ThisApplication.ActiveDocument.DocumentType
		Case kPartDocumentObject 'Part = kAssemblyDocumentObject = 12290
			Dim oPartDoc as PartDocument
			oPartDoc = ThisApplication.ActiveDocument
			Planes_Visibilty(oPartDoc.ComponentDefinition)
		Case kAssemblyDocumentObject 'Assembly = kAssemblyDocumentObject = 12291
			Dim oAsmDoc As AssemblyDocument
			oAsmDoc = ThisApplication.ActiveDocument			
			Planes_Visibilty(oAsmDoc.ComponentDefinition)
			Dim oDoc As Document
			For Each oDoc In oAsmDoc.AllReferencedDocuments
				If oDoc.ComponentDefinition.IsiPartMember = False Then
					Planes_Visibilty(oDoc.ComponentDefinition)
				End If
			Next
		Case kDrawingDocumentObject 'Drawing = kDrawingDocumentObject = 12292
	End Select
End Sub

Sub Planes_Visibilty (ByVal oDef As ComponentDefinition)

	For Each oWorkPlane In oDef.WorkPlanes	

		Select Case oWorkPlane.Name
			Case "YZ Plane - RIGHT", "XZ Plane - TOP", "XY Plane - FRONT"
			Case "YZ Plane"
				oWorkPlane.Name = "YZ Plane - RIGHT"
			Case "XZ Plane"
				oWorkPlane.Name = "XZ Plane - TOP"
			Case "XY Plane"
				oWorkPlane.Name = "XY Plane - FRONT"
			Case Else
				'MessageBox.Show("Planos não encontrados", "Planos")
		End Select
		oWorkPlane.Visible = False
	Next
	
End Sub

Please free to contact if there is any doubt.

 

If solves problem, click on "Accept as solution" / give a "Kudo".

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 13 of 16

amarcoc
Advocate
Advocate

Thank you for the reply.

 

It doesnt work on iAssembly.

 

Assembly in attachment with iPart and iAssembly included.

 

The macro is already built in the test.iam

 

 

0 Likes
Message 14 of 16

chandra.shekar.g
Autodesk Support
Autodesk Support

Hi @amarcoc,

 

For some reason,  unable to rename iPart workPlanes. Other than that everything is working fine.

 

Try the following modified iLogic code.

 

Sub Main ()	
	Select Case ThisApplication.ActiveDocument.DocumentType
		Case kPartDocumentObject 'Part = kAssemblyDocumentObject = 12290
			Dim oPartDoc as PartDocument
			oPartDoc = ThisApplication.ActiveDocument
			Planes_Visibilty(oPartDoc.ComponentDefinition)
		Case kAssemblyDocumentObject 'Assembly = kAssemblyDocumentObject = 12291
			Dim oAsmDoc As AssemblyDocument
			oAsmDoc = ThisApplication.ActiveDocument			
			Planes_Visibilty(oAsmDoc.ComponentDefinition)
			Dim oDoc As Document
			For Each oDoc In oAsmDoc.AllReferencedDocuments
				Select Case oDoc.DocumentType
					Case kPartDocumentObject 
						Dim part As PartDocument
						part = oDoc
						If oDoc.ComponentDefinition.IsiPartMember = False Then
							Planes_Visibilty(oDoc.ComponentDefinition)
						End If				
					Case kAssemblyDocumentObject
						Dim assy As AssemblyDocument
						assy = oDoc
						Planes_Visibilty(assy.ComponentDefinition)					
				End Select
			Next
		Case kDrawingDocumentObject 'Drawing = kDrawingDocumentObject = 12292
	End Select
End Sub

Sub Planes_Visibilty (ByVal oDef As ComponentDefinition)
	
	For Each oWorkPlane In oDef.WorkPlanes	

		Select Case oWorkPlane.Name
			Case "YZ Plane - RIGHT", "XZ Plane - TOP", "XY Plane - FRONT"
			Case "YZ Plane"
				oWorkPlane.Name = "YZ Plane - RIGHT"
			Case "XZ Plane"
				oWorkPlane.Name = "XZ Plane - TOP"
			Case "XY Plane"
				oWorkPlane.Name = "XY Plane - FRONT"
			Case Else
				'MessageBox.Show("Planos não encontrados", "Planos")
		End Select
		oWorkPlane.Visible = False
	Next
	
End Sub

Please feel free to contact if there is any doubt.

 

If solves problem, click on "Accept as solution" / give a "Kudo".

 

Thanks and regards, 


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 15 of 16

Anonymous
Not applicable

Hi,

 

I saw your code and wondered if it was possible to alter it... Can it be modified so that when run from an .idw all planes with the Name "Datum" are "include" in the drawing view???

 

Thanks for your help

M

0 Likes
Message 16 of 16

chandra.shekar.g
Autodesk Support
Autodesk Support

Hi @Anonymous,

 

Can you please explain with more details?

 

Name with "Datum" means before or after work plane name.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes