3 Replies Latest reply on Mar 16, 2015 1:29 AM by Di Anne

    Move Folder After Origin

    Di Anne

      Hi SW Community,


      I'm working on this macro to organize each component into folders.

      But I need to move one specific folder and move it to the top


      Does anyone knows how to do this?


      By the way I'm using SW2012.


      Thanks in advance.





      Keith Rice

        • Re: Move Folder After Origin
          Deepak Gupta

          There is no direct way but here is a tricky macro from Artem that should do the work: Re: Insert second feature tree folder

          • Re: Move Folder After Origin
            Keith Rice

            If I were to write this macro, here's how I would do it:


            1. Precondition: the folder to move after the origin is selected


            2. Use ISelectionMgr::GetSelectedObject6 to get IFeature, then IFeature::GetSpecificFeature2 to get IFeatureFolder, then Get the pointers of all of the features in the original folder using IFeatureFolder::GetFeatures.


            3. Delete the selected folder using IModelDoc2::EditDelete


            4. Use Artem's code, which Deepak linked to above, to create a new folder after the origin. This macro takes advantage of the fact that you can rollback an assembly using the API --- something you actually can't do manually.


            5. Get the pointer to this new folder using IModelDocExtension::GetLastFeatureAdded


            6. Use IAssemblyDoc::ReorderComponents to move the features to the new folder. Shouldn't be hard, since you should have the pointers for these features (step 2) and new the folder (step 5).


            Note that IAssemblyDoc::ReorderComponents only works with components at the top level or within a single assembly. You cannot move components from one sub-assembly to another, from the top level to a sub-assembly, or from the sub-assembly to the top level, it appears.



            SolidWorks API Tutorials

            • Re: Move Folder After Origin
              Di Anne

              Hi Deepak Gupta, Keith Rice


              Thanks a lot.. It was a big help.