Hi,
I have the following piece of code to collapse all children:
Set oDoc = ThisApplication.ActiveEditDocument Dim oTopNode As BrowserNode Set oTopNode = oDoc.BrowserPanes.ActivePane.TopNode Dim oNode As BrowserNode For Each oNode In oTopNode.BrowserNodes 'If the node is visible and expanded, collapse it If oNode.Visible = True And oNode.Expanded = True Then oNode.Expanded = False End If Next
This works for the topassembly, but not for the subassembly. See attachment for a screenshot of my browser. So, the code works if Assembly101 is active (every node is collapsed), but it does not work if Assembly100 is active.
Why does it not work and how do I need to change my code to make it work?
And why does the following code not work (for the topassembly as well as subassemblies)?:
Set oCtrlDef = ThisApplication.CommandManager.ControlDefinitions("AppBrowserCollapseChildrenCmd") oCtrlDef.Execute Set oCtrlDef = ThisApplication.CommandManager.ControlDefinitions("AppBrowserCollapseAllCmd") oCtrlDef.Execute
Thanks in advance,
Dominiek
... It only works for the top level nodes because you dont tell it to go any deeper.
You need some sort of other recursion and looping to follow it down the levels of nodes and run the functionality from there.
@MechMachineMan wrote:... It only works for the top level nodes because you dont tell it to go any deeper.
You need some sort of other recursion and looping to follow it down the levels of nodes and run the functionality from there.
With this code:
Set oDoc = ThisApplication.ActiveEditDocument
and this code:
Set oTopNode = oDoc.BrowserPanes.ActivePane.TopNode
I have the "Sub"Node.
I even tested it with the following:
Dim test As String test = oTopNode.FullPath
And I got the name of the subassembly.
So I tell to go deeper, but you say I don't. What am I missing here?
You need something like: EXCEPT you need to write it as 2 seperate functions and call recursively.
Set oDoc = ThisApplication.ActiveEditDocument Dim oTopNode As BrowserNode Set oTopNode = oDoc.BrowserPanes.ActivePane.TopNode Dim oNode As BrowserNode For Each oNode In oTopNode.BrowserNodes 'If the node is visible and expanded, collapse it
If oNode.Nodes.Count > 0
For Each oNode in oNode.Nodes
Visible off
Next
End if
If oNode.Visible = True And oNode.Expanded = True Then oNode.Expanded = False End If
Next
RECURSION like this:
Public Sub TraverseAssemblySample() ' Get the active assembly. Dim oAsmDoc As AssemblyDocument Set oAsmDoc = ThisApplication.ActiveDocument Debug.Print oAsmDoc.DisplayName ' Call the function that does the recursion. Call TraverseAssembly(oAsmDoc.ComponentDefinition.Occurrences, 1) End Sub Private Sub TraverseAssembly(Occurrences As ComponentOccurrences, _ Level As Integer) ' Iterate through all of the occurrence in this collection. This ' represents the occurrences at the top level of an assembly. Dim oOcc As ComponentOccurrence For Each oOcc In Occurrences ' Print the name of the current occurrence. Debug.Print Space(Level * 3) & oOcc.Name ' Check to see if this occurrence represents a subassembly ' and recursively call this function to traverse through it. If oOcc.DefinitionDocumentType = kAssemblyDocumentObject Then Call TraverseAssembly(oOcc.SubOccurrences, Level + 1) End If Next End Sub