Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Create subfolder in an assembly

Anonymous

Create subfolder in an assembly

Anonymous
Not applicable

Hi.

 

Is it possible to create a subfolder in an assembly document? I just want to create something like this:

 

Folder 1

       |

       ------> Folder 2

 

where Folder 2 is created through API.

 

I know how to create a folder on TopNode level in browser but I cannot find any way to create another one within it. A solution which allows to create a Folder 2 on TopNode level and then moving it inside Folder 1 will be also good.

0 Likes
Reply
Accepted solutions (1)
962 Views
1 Reply
Reply (1)

BrianEkins
Mentor
Mentor
Accepted solution

You can't directly create a new folder within another folder.  However, you can create a new folder at the top level and then move it into another folder, which results in the same thing.  Below are two VBA macros that do this in different ways.  The first creates the two folders and then moves one into the other.  The other creates the subfolders first and then moves them into the top folder during its creation. 

 

There's one weird behavior of Inventor that you can't reorder folders if that's all that's in the assembly.  This means the first program will fail if run with an empty assembly.  However, it works if there's even one occurrence.  You see the same behavior in the UI.  The second program works even in an empty assembly.  So the second example is probably the best approach.

 

Public Sub BrowserFolders1()
    Dim asmDoc As AssemblyDocument
    Set asmDoc = ThisApplication.ActiveDocument
    
    Dim pane As BrowserPane
    Set pane = asmDoc.BrowserPanes.ActivePane
    
    Dim topFolder As BrowserFolder
    Set topFolder = pane.AddBrowserFolder("Top Folder")
    
    Dim subFolder As BrowserFolder
    Set subFolder = pane.AddBrowserFolder("Sub Folder")
    
    Call topFolder.Add(subFolder.BrowserNode)
End Sub

Public Sub BrowserFolders2()
    Dim asmDoc As AssemblyDocument
    Set asmDoc = ThisApplication.ActiveDocument
    
    Dim pane As BrowserPane
    Set pane = asmDoc.BrowserPanes.ActivePane
    
    Dim subFolder1 As BrowserFolder
    Set subFolder1 = pane.AddBrowserFolder("Sub Folder 1")
    
    Dim subFolder2 As BrowserFolder
    Set subFolder2 = pane.AddBrowserFolder("Sub Folder 2")
    
    Dim folders As ObjectCollection
    Set folders = ThisApplication.TransientObjects.CreateObjectCollection
    Call folders.Add(subFolder1.BrowserNode)
    Call folders.Add(subFolder2.BrowserNode)
    
    Dim topFolder As BrowserFolder
    Set topFolder = pane.AddBrowserFolder("Top Folder", folders)
End Sub

 

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com