I am trying to create folders and subfolders in the feature tree. I have found that with the InsertFeatureTreeFolder2 method, you can create empty folders or folders that contain existing features, but the API help doesn't clarify if it can contain existing folder features, thereby turning the existing folders into subfolders of the new folder.
The help for the InsertSubFolder method explicitly states that it can move existing body subfolders into a new folder. I am hoping the same is true of 'regular' folders per InsertFeatureTreeFolder2.
I have not been able to find any other discussions or examples that answer my question and can't afford to put in a lot of effort only to discover that there might a 'no subfolders' limitation to the InsertFeatureTreeFolder2 method.
Thank You,
Can you create Subfolders in the Feature Tree?
Re: Can you create Subfolders in the Feature Tree?
I have used InsertFeatureTreeFolder2 to create empty folders but it should work to add folders (making them sub folders) as well.
You will have to have the desired folders selected.
I just tested it, and it works OK, and moved the selected folders into the new folder.
You will have to have the desired folders selected.
I just tested it, and it works OK, and moved the selected folders into the new folder.
Deepak Gupta
SOLIDWORKS Consultant/Blogger
SOLIDWORKS Consultant/Blogger
Re: Can you create Subfolders in the Feature Tree?
Thank you, Deepak!
- Stefan Sterk
- Posts: 45
- Joined: Tue Aug 10, 2021 2:40 am
- x 67
- x 85
Re: Can you create Subfolders in the Feature Tree?
Hi Loeb,
You could use ReorderFeature' to place a new 'sub' folder within a folder. As shown in the code below.
You could use ReorderFeature' to place a new 'sub' folder within a folder. As shown in the code below.
Code: Select all
Sub main()
Set swApp = Application.SldWorks
Set swDoc = swApp.ActiveDoc
If swDoc Is Nothing Then End
If swDoc.GetType <> 1 And swDoc.GetType <> 2 Then End
Set swDocExt = swDoc.Extension
Set swSelMgr = swDoc.SelectionManager
Set swFeatMgr = swDoc.FeatureManager
If swSelMgr.GetSelectedObjectType3(1, -1) <> 94 Then MsgBox "Please select a folder": End
' Get selected folder
Set swFeatFolder = swSelMgr.GetSelectedObject6(1, -1)
' Create new empty 'sub' folder
Set swFeatSubFolder = swFeatMgr.InsertFeatureTreeFolder2(swFeatureTreeFolderType_e.swFeatureTreeFolder_EmptyBefore)
' Move 'sub' folder inside selected folder
bRet = swDocExt.ReorderFeature(swFeatSubFolder.Name, swFeatFolder.Name, swMoveLocation_e.swMoveToFolder)
If bRet Then MsgBox "Created subfolder '" & swFeatSubFolder.Name & "' inside folder '" & swFeatFolder.Name & "'."
End Sub
Re: Can you create Subfolders in the Feature Tree?
Stefan,Stefan Sterk wrote: ↑Wed Feb 12, 2025 4:36 pm Hi Loeb,
You could use ReorderFeature' to place a new 'sub' folder within a folder. As shown in the code below.
Thanks, that's exactly what I'm looking for. I had already found ReorderComponent, but didn't realize that ReorderFeature was an available method.
Since a folder is actually more than one feature (FtrFolder, ___EndTag___, and any contents that might be in the folder), I'll have to figure out how that works. If you move the FtrFolder feature, does all the rest automatically go with it?