Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
WCrihfield
in reply to: Anonymous

Since you can access the API by several different means, I thought I would show the regular iLogic way to do it.

Here is a simple iLogic rule you can use to toggle the visibility of all 3D sketches in all parts within the active assembly.

If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
	MsgBox("This rule '" & iLogicVb.RuleName & "' only works for Assembly Documents.",vbOKOnly, "WRONG DOCUMENT TYPE")
	Return
End If

Dim oADoc As AssemblyDocument = ThisAssembly.Document
Dim oOnOff As Boolean
For Each oRefDoc As Document In oADoc.AllReferencedDocuments
	If oRefDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
		Dim oPDoc As PartDocument = oRefDoc
		If oPDoc.ComponentDefinition.Sketches3D.Count > 0 Then
			For Each oSketch3D As Sketch3D In oPDoc.ComponentDefinition.Sketches3D
				oOnOff = oSketch3D.Visible
				oSketch3D.Visible = (Not oOnOff)
			Next
		End If
	End If
Next

If you want to change this rule from a toggle functionality to a direct (turn them all off) functionality, all you need to do is

  • assign the value of False to the Boolean variable near the beginning of the code (it should already be false though, by default)
  • Replace these two lines [oOnOff = oSketch3D.Visible] & [oSketch3D.Visible = (Not oOnOff)] with the following:
  • oSketches3D.Visible = oOnOff

Like this:

If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
	MsgBox("This rule only works for Assembly Documents.",vbOKOnly, "WRONG DOCUMENT TYPE")
	Return ' or Exit Sub
End If

Dim oADoc As AssemblyDocument = ThisAssembly.Document
Dim oOnOff As Boolean = False
For Each oRefDoc As Document In oADoc.AllReferencedDocuments
	If oRefDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
		Dim oPDoc As PartDocument = oRefDoc
		If oPDoc.ComponentDefinition.Sketches3D.Count > 0 Then
			For Each oSketch3D As Sketch3D In oPDoc.ComponentDefinition.Sketches3D
				oSketch3D.Visible = oOnOff
			Next
		End If
	End If
Next

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click 'LIKE' :thumbs_up:.

If you have time, please... Vote For My IDEAS :light_bulb:and Explore My CONTRIBUTIONS

Inventor 2020 Help | Inventor Forum | Inventor Customization Forum | Inventor Ideas Forum

Wesley Crihfield

EESignature

(Not an Autodesk Employee)