3 Replies Latest reply on Oct 12, 2012 1:48 AM by Oleg Bezyaev

    Insert second feature tree folder

    Oleg Bezyaev

      Good day for all!

      There is an assembly with the folder which is inserted right after "OriginProfileFeature". How to me to insert new folder after "OriginProfileFeature" and before my folder?

        • Re: Insert second feature tree folder
          Deepak Gupta

          This code will generate an empty folder before a selected component or feature only (not contained inside a folder). Not able to find any API codes for placing a folder before a folder.


          Option Explicit


          Sub main()



              Dim swApp                   As SldWorks.SldWorks

              Dim swModel                 As SldWorks.ModelDoc2

              Dim swFeatMgr               As SldWorks.FeatureManager

              Dim swFeat                  As SldWorks.Feature

              Dim bRet                    As Boolean


              Set swApp = CreateObject("SldWorks.Application")

              Set swModel = swApp.ActiveDoc

              Set swFeatMgr = swModel.FeatureManager

              Set swFeat = swFeatMgr.InsertFeatureTreeFolder2(swFeatureTreeFolder_EmptyBefore)


              ' Return NULL if unable to create the folder



              If Not swFeat Is Nothing Then

                  swFeat.Name = swFeat.Name & "_NEW"

              End If

          End Sub

          • Re: Insert second feature tree folder
            Artem Taturevych

            Hi Oleg,


            As Deepak says there is no direct API for doing this. Furthermore it is explicitly mentioned that the Folder feature cannot be used as the reference for other folder feature.


            I have written some trick-macro which actually does the case. Please find it in the attachment. Hope it helps.




            Artem Taturevych

            Application Engineer at Intercad


            Tel: +61 2 9454 4444

              • Re: Insert second feature tree folder
                Oleg Bezyaev

                Hi Artem. Cool solution!

                I went a different way:

                while traverse on components, run CreateFolders ()

                private string SelectFirstComp()


                            Feature swFeature1 = (Feature)swModel.FirstFeature();

                            for (int i = 0; i < 100; i++)


                                string typeFeat = swFeature1.GetTypeName();

                                if (typeFeat == "Reference")


                                    string assyName = swModel.GetTitle().Substring(0, swModel.GetTitle().Length - 7);

                                    string featName = swFeature1.Name;

                                    string fullName = featName + "@" + assyName;

                                    swModel.Extension.SelectByID2(fullName, "COMPONENT", 0, 0, 0, true, 0, null, 0);

                                    return fullName;


                                swFeature1 = (Feature)swFeature1.GetNextFeature();


                            return null;



                private void CreateFolders()


                            foreach (string name in Names)


                                    string myComp = SelectFirstComp();

                                    Feature feature = default(Feature);

                                    FeatureManager featureMgr = (FeatureManager)swModel.FeatureManager;

                                    feature = featureMgr.InsertFeatureTreeFolder2((int)swFeatureTreeFolderType_e.swFeatureTreeFolder_EmptyBefore);

                                    feature.Name = name;


                            folderUge = true;


                In this case folders must be empty.

                I mean, first create all the necessary folders, and then fill them.


                Not able to find any API codes for placing a folder before a folder.

                So I went a little different way. Create a folder, and then drag and drop them. But the solution Artem can help me deal with the problem.