iLogic coding help.

iLogic coding help.

andrew_wade1
Participant Participant
446 Views
2 Replies
Message 1 of 3

iLogic coding help.

andrew_wade1
Participant
Participant

I am looking to write a iLogic code to turn off visibility of planes, sketches, datums, points... To help clean up both part and assembly files. At the same time at the end bring the part or assembly back to home and fit. I have started with basic vb code and kind of got it to work with the parts but not the assembly. Thank you. 

0 Likes
Accepted solutions (1)
447 Views
2 Replies
Replies (2)
Message 2 of 3

patrick.schlambHPACQ
Participant
Participant

Here is a very basic set of code to turn off the object visibility and set the view to home. There are a lot of options within the object visibility that you can dig deeper into. This acts the same as just turning off the object visibility in the View tab of the ribbon. 

 

Sub Main()
	Dim doc As AssemblyDocument = ThisDoc.Document
	Dim objVis As ObjectVisibility = doc.ObjectVisibility
	
	objVis.AllWorkFeatures = False
	
	ThisApplication.CommandManager.ControlDefinitions.Item("AppViewCubeHomeCmd").Execute
    ThisApplication.ActiveView.Fit
	
End Sub 'Main

 

0 Likes
Message 3 of 3

WCrihfield
Mentor
Mentor
Accepted solution

Hi @andrew_wade1.  This task has been a relatively popular one on this forum over the years, so if you used the search functionality of this forum, you will likely see lots of other conversations about it, and lots of other example codes you could try out.  Many of them only turn off work features, such as WorkPoints, WorkAxes, and WorkPlanes, but some also work with other types of things.  Below is an example iLogic rule you can try out for a task like that.

 

However, this can be a relatively complex task, with lots of different aspects and details involved, each of which may cause this task to not work exactly as planned.  Visibility settings are saved within the DesignViewRepresentations that are within the RepresentationsManager of the ComponentDefinition, within each document.  Then, every individual assembly component occurrence can each have their DVR (DesignViewRepresentation) set differently, which potentially means different appearances or visibility settings.  If you are not using all the DVR settings along the way in each document and in each occurrence, then this may not work properly for you.

Sub Main
	Dim oDoc As Inventor.Document = ThisDoc.Document
	Dim oTrans As Inventor.Transaction
	oTrans = ThisApplication.TransactionManager.StartTransaction(oDoc, "Set Visibility - iLogic")
	SetVisibility(oDoc, False)
	Dim oRefDocs As DocumentsEnumerator = oDoc.AllReferencedDocuments
	For Each oRefDoc As Inventor.Document In oRefDocs
		SetVisibility(oRefDoc, False)
	Next oRefDoc
	oDoc.Update2(True)'do not use 'If oDoc.RequiresUpdate', it will be False
	oTrans.End
	'If oDoc.Dirty Then oDoc.Save2(True)
End Sub

Sub SetVisibility(oDoc As Document, bVisible As Boolean)
	If oDoc Is Nothing OrElse oDoc.IsModifiable = False Then Return
	If (Not TypeOf oDoc Is AssemblyDocument) AndAlso (Not TypeOf oDoc Is PartDocument) Then Return
	Dim oCD As ComponentDefinition = oDoc.ComponentDefinition
	For Each oWA As WorkAxis In oCD.WorkAxes
		If oWA.Visible <> bVisible Then oWA.Visible = bVisible
	Next
	For Each oWP As WorkPlane In oCD.WorkPlanes
		If oWP.Visible <> bVisible Then oWP.Visible = bVisible
	Next
	For Each oWPt As WorkPoint In oCD.WorkPoints
		If oWPt.Visible <> bVisible Then oWPt.Visible = bVisible
	Next
	Try 'assemblies do not have these, only parts
		For Each oWS As WorkSurface In oCD.WorkSurfaces
			If oWS.Visible <> bVisible Then oWS.Visible = bVisible
		Next
	Catch : End Try
	For Each oSketch As PlanarSketch In oCD.Sketches
		If oSketch.Visible <> bVisible Then oSketch.Visible = bVisible
	Next
	Try 'assemblies do not have these, only parts
		For Each o3DSketch As Sketch3D In oCD.Sketches3D
			If o3DSketch.Visible <> bVisible Then o3DSketch.Visible = bVisible
		Next
	Catch : End Try
	For Each oMA As ModelAnnotation In oCD.ModelAnnotations
		If oMA.Visible <> bVisible Then oMA.Visible = bVisible
	Next
	'oDoc.Update2(True)
End Sub

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes