Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Make feature sketch invisible in an assembly

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
Hubert_Los
467 Views, 6 Replies

Make feature sketch invisible in an assembly

Hi,
How to make invisible all the feature sketches that are make visible in the assembly?

Hubert_Los_1-1686639141147.png

 

Tags (1)
6 REPLIES 6
Message 2 of 7

Hi @Hubert_Los . Try this iLogic code. It makes all sketches in all components of the main assembly invisible.

 

 

Private Sub Main()
	Dim oDoc As AssemblyDocument = ThisApplication.ActiveDocument
	Dim oTrans As Transaction = ThisApplication.TransactionManager.StartTransaction(oDoc, "SetVisibleSketch")
	For Each oRefDoc As Document In oDoc.AllReferencedDocuments
		If TypeOf oRefDoc Is PartDocument And oRefDoc.IsModifiable Then
			Dim oPDoc As PartDocument = oRefDoc
			Call SetVisibleSketch(oPDoc.ComponentDefinition.Sketches)
		End If
	Next
	oTrans.End()
End Sub

Private Function SetVisibleSketch(oSkets As PlanarSketches, Optional bVisible As Boolean = False)
	For i As Integer = 1 To oSkets.Count
		If oSkets.Item(i).Visible Then oSkets.Item(i).Visible = bVisible
	Next
End Function

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

Message 3 of 7
Hubert_Los
in reply to: Hubert_Los

Hi @Andrii_Humeniuk ,

Unfortunately your code only works on "shered skeches" I have a different situation. I enable sketch editing from the assembly level and this sketch is not share.

Message 4 of 7

Not sure I understood you correctly, but made the changes to the code. Now the visibility of sketches is turned off in the main assembly and in subassemblies and in details. The code also includes a check for the ability to modify documents.

Private Sub Main()
	Dim oDoc As AssemblyDocument = ThisApplication.ActiveDocument
	Dim oTrans As Transaction = ThisApplication.TransactionManager.StartTransaction(oDoc, "SetVisibleSketch")
	If oDoc.IsModifiable Then Call SetVisibleSketch(oDoc.ComponentDefinition.Sketches)
	For Each oRefDoc As Document In oDoc.AllReferencedDocuments
		If oRefDoc.IsModifiable Then
			Call SetVisibleSketch(oRefDoc.ComponentDefinition.Sketches)
		End If
	Next
	oTrans.End()
End Sub

Private Function SetVisibleSketch(oSkets As PlanarSketches, Optional bVisible As Boolean = False)
	For i As Integer = 1 To oSkets.Count
		On Error Resume Next
		If oSkets.Item(i).Visible Then oSkets.Item(i).Visible = bVisible
	Next i
End Function

 

 

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

Message 5 of 7
Hubert_Los
in reply to: Hubert_Los

Sorry, but it doesn't work. I'm sending a video of what sketch I mean

 

Message 6 of 7

Hi @Hubert_Los . I finally understood you. Thanks for the video explaining what you need it really helped. Here is the code that determines the visibility of all proxy skeaths and makes them invisible:

Private Sub Main()
	Dim oDoc As AssemblyDocument = ThisApplication.ActiveDocument
	Dim oTrans As Transaction = ThisApplication.TransactionManager.StartTransaction(oDoc, "SetVisibleSketch")
	Call SetVisibleSketch(oDoc.ComponentDefinition.Occurrences)
	oTrans.End()
End Sub

Private Function SetVisibleSketch(oOccs As ComponentOccurrences, Optional bVisible As Boolean = False)
	For Each oOcc As ComponentOccurrence In oOccs
		If oOcc.DefinitionDocumentType = DocumentTypeEnum.kPartDocumentObject Then
			On Error Resume Next
			Dim oOccDef As PartComponentDefinition = oOcc.Definition
			For Each oSketch As PlanarSketch In oOccDef.Sketches
				Dim oSketchProxy As PlanarSketchProxy : oOcc.CreateGeometryProxy(oSketch, oSketchProxy)
				If oSketchProxy.Visible Then oSketchProxy.Visible = False
			Next
		Else If oOcc.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
			If oOcc.SubOccurrences.Count > 0 Then
				Call SetVisibleSketch(oOcc.SubOccurrences)
			End If
		End If
	Next
End Function

 

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

Message 7 of 7
Hubert_Los
in reply to: Hubert_Los

Now it works, thank you 🙂

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report