Announcements

Starting in December, we will archive content from the community that is 10 years and older. This FAQ provides more information.

Make feature sketch invisible in an assembly

Hubert_Los
Advocate
Advocate

Make feature sketch invisible in an assembly

Hubert_Los
Advocate
Advocate

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

Hubert_Los_1-1686639141147.png

 

0 Likes
Reply
Accepted solutions (1)
482 Views
6 Replies
Replies (6)

Andrii_Humeniuk
Advisor
Advisor

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

0 Likes

Hubert_Los
Advocate
Advocate

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.

0 Likes

Andrii_Humeniuk
Advisor
Advisor

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

0 Likes

Hubert_Los
Advocate
Advocate

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

 

0 Likes

Andrii_Humeniuk
Advisor
Advisor
Accepted solution

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

0 Likes

Hubert_Los
Advocate
Advocate

Now it works, thank you 🙂

0 Likes