Have existing folder in the feature tree Named "MBI"
How do I move an selected Component into the "MBI" folder with theAPI functions?SolidworksApi macros
How do I move an selected Component into the "MBI" folder with theAPI functions?SolidworksApi macros

Have a look at
AssemblyDoc::ReorderComponents
If you are having trouble with it reply here and i'll try to giveyou more info.
Cheers,
--Stav.
Stavros Antoniou wrote:
Have a look at
AssemblyDoc::ReorderComponents
If you are having trouble with it reply here and i'll try to giveyou more info.
I tried to use this method, but doesn't work ...
I insert a new folder and rename it - ok, it works
I get all components of the assembly in an array - ok, it works
I filter the components, which I want move to the folder in a newarray - ok, it works
now i callAssemblyDoc::ReorderComponents with the parameters: newarray of pointers of filtered components, pointer of new folder andwhere=swReorderComponents_LastInFolder
But it doesn't work! The return value is always false! And nocomponent is moved to the folder! Why? What's wrong?
All the filtered components are one behind the other in theFeatureManager-Tree - whithout a gap.
It doesn't work also with only one component to move!
OK - I know I can also select the components before inserting thenew folder - that works - the selected components are moved in thenew created folder.
But I need to move components into an existing folder.
Can anybody help?
I will asssume that the folder already exists and its name is"MyFolder", i will also assume that you have selected all thecompoents you want to move in the folder. The macro below does justthat.
Now if you want to also create the folder use this function insteadInsertFeatureTreeFolder2
The function above inserts the preselected components in the newlycreated folder.
If you have further issues let me know.
Cheers,
--Stav.
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim modeldoc As SldWorks.ModelDoc2
Dim asmDoc As SldWorks.AssemblyDoc
Dim selMgr As SldWorks.SelectionMgr
Dim myFeature As SldWorks.Feature
Dim componentsToMove() As SldWorks.Component2
Dim i As Integer, count As Integer
Dim boolstatus As Boolean
Sub main()
Set swApp = Application.SldWorks
Set modeldoc = swApp.ActiveDoc
Set asmDoc = modeldoc
Set selMgr = modeldoc.SelectionManager
count = selMgr.GetSelectedObjectCount2(0)
ReDim componentsToMove(count - 1)
For i = 0 To count - 1
Set componentsToMove(i) = selMgr.GetSelectedObjectsComponent3(i +1, 0)
Next
Set myFeature = asmDoc.FeatureByName("MyFolder")
modeldoc.ClearSelection2 True
boolstatus = asmDoc.ReorderComponents(componentsToMove, myFeature,swReorderComponentsWhere_e.swReorderComponents_LastInFolder)
End Sub
now my macro also works!
The Problem was: I wrote it in late binding!
The methode AssemblyDoc.ReorderComponents works ONLY with earlybinding and the object has to be AssemblyDoc, ModelDoc2 as objectis not enough!
Iv created a folder using this api call set swFeatFolder = swFeatMgr.InsertFeatureTreeFolder2(swFeatureTreeFolder_Containing)
I can create a folder called Folder1, My sketches move into that folder no issues.
Does any know how to make all my sketch move into that folder everytime I run my macro?
the macro seems to want to make a new folder every time.
Thanks
-Jakob