10-26-2020
07:22 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
10-26-2020
07:22 AM
Try this code. It searches through all the browser nodes until it finds a 3D Sketch and turns it off. This should work for setting visibility of other types of objects as well.
To set visibility, change the second parameter of the first line that starts with "Call"
Public Sub Set3DSketchVisibility()
Dim thisAssembly As Document
Set thisAssembly = ThisApplication.ActiveDocument
If ThisApplication.ActiveDocumentType <> kAssemblyDocumentObject Then
MsgBox ("This macro can only be run in assembly documents")
Exit Sub
End If
'get the model browser pane
Dim oModelBrowserPane As BrowserPane
Set oModelBrowserPane = thisAssembly.BrowserPanes.item("Model")
'search through all browser nodes and set visibility of sketches found
'set the second parameter to true or false based on whether you want to hide or show 3d sketches
Call SearchNodes(oModelBrowserPane.TopNode.BrowserNodes, True)
End Sub
Private Sub SearchNodes(oNode As BrowserNodesEnumerator, sketchVisiblilty As Boolean)
'set instance objects
Dim oSubNode As BrowserNode
Dim o3DSketch As Sketch3DProxy
'quits routine when it comes to a node that is empty
If oNode.Count = 0 Then
Exit Sub
End If
'search through nodes
For Each oSubNode In oNode
'if node contains child nodes, search through those
If oSubNode.BrowserNodes.Count > 0 Then
Call SearchNodes(oSubNode.BrowserNodes, sketchVisiblilty)
End If
'search for 3D Sketches and set the visiblity
If Not oSubNode.NativeObject Is Nothing Then
If oSubNode.NativeObject.Type = kSketch3DProxyObject Then
Set o3DSketch = oSubNode.NativeObject
o3DSketch.Visible = sketchVisiblilty
End If
End If
Next
End Sub