SketchEntity Visibility Hide/Unhide

SketchEntity Visibility Hide/Unhide

Inventor30Dev
Participant Participant
247 Views
4 Replies
Message 1 of 5

SketchEntity Visibility Hide/Unhide

Inventor30Dev
Participant
Participant

I was not able to hide SketchEntities within a PartDocument.

There is no "Visibile" Property.

 

If i unterstood correctly the SketchEntity has a Layer property which has a Visibility property, as in: SketchEntity.Layer.Visible

but I was not able to assign any Layer since i didn't find a way to get access to Layers within a PartDocument.

 

DrawingDocument on the other hand has a StylesManager which has 100 different Layers to chose from. I have even tried to take the Layers from there and assign it to SketchEntity.Layer which gave an exception.

 

At the moment a workaround is used where the data from the SketchEntity is saved and the SketchEntity Deleted and Recreated when needed. But constrains will then be lost.

 

Any suggestions?

0 Likes
248 Views
4 Replies
Replies (4)
Message 2 of 5

C_Haines_ENG
Collaborator
Collaborator

If you are just trying to change the visibility of a sketch in a part document, there is no "Layer" property.

 

Dim oDoc As PartDocument = ThisDoc.Document

For Each oSketch As PlanarSketch In oDoc.ComponentDefinition.Sketches
	
	oSketch.Visible = False
	
Next
0 Likes
Message 3 of 5

tim11_manhhieu
Advocate
Advocate

Try this, hide and unhide in 1 button

Option Explicit

Sub ShowHideSketches()

If countSketchShow = 1 Then
    Call HideSketches
Else: Call ShowSketches
End If

End Sub

Sub ShowSketches()

Dim doc As PartDocument
Set doc = ThisApplication.ActiveDocument

Dim oSketch As PlanarSketch

For Each oSketch In doc.ComponentDefinition.Sketches
        oSketch.Visible = True
Next

End Sub

Sub HideSketches()

Dim doc As PartDocument
Set doc = ThisApplication.ActiveDocument

Dim oSketch As PlanarSketch

For Each oSketch In doc.ComponentDefinition.Sketches
        oSketch.Visible = False
Next

End Sub

Function countSketchShow() As Integer

Dim doc As PartDocument
Set doc = ThisApplication.ActiveDocument

Dim oSketch As PlanarSketch
Dim count As Integer

For Each oSketch In doc.ComponentDefinition.Sketches
        If oSketch.Visible = True Then
            count = count + 1
            Exit For
        End If
Next

countSketchShow = count

End Function
0 Likes
Message 4 of 5

Inventor30Dev
Participant
Participant

Thank you for the responses.
But I need to be able to hide a single SketchEntity within a Sketch,
not all the SketchEntities like in both code examples above.
Is there any solution for that?

0 Likes
Message 5 of 5

C_Haines_ENG
Collaborator
Collaborator

Are you talking about hiding a line WITHIN a sketch? That's not possible, and should not be apart of any workflow. 

0 Likes