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: 

Collapse All Children in SubAssembly (ActiveEditDocument)

3 REPLIES 3
Reply
Message 1 of 4
dominiek_vanwest
709 Views, 3 Replies

Collapse All Children in SubAssembly (ActiveEditDocument)

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

3 REPLIES 3
Message 2 of 4

... 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.


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
Message 3 of 4


@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?

Message 4 of 4

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

 

 


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type

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

Post to forums  

Autodesk Design & Make Report