Moving parts between groups/folders

Moving parts between groups/folders

MTheDesigner
Advocate Advocate
497 Views
4 Replies
Message 1 of 5

Moving parts between groups/folders

MTheDesigner
Advocate
Advocate

Hi everyone, 

 

I am working on a project right now where I have a reference parts folder I need to be able to move parts and sub assemblies in and out of this folder. I am unaware of any tools to deal with this though. 

0 Likes
Accepted solutions (1)
498 Views
4 Replies
Replies (4)
Message 2 of 5

WCrihfield
Mentor
Mentor

Hi @MTheDesigner.  I take it that since you are posting this in the iLogic/API forum, you want to be able to move these files by code, right?  Well here are 3 lines of code representing the most common methods of moving files by code.  Some of these offer more options beyond the first two input variables too.  (Link1, Link2, Link3)

ThisApplication.FileManager.MoveFile(oSourceFileName, oDestinationFileName)
System.IO.File.Move(oSourceFileName, oDestinationFileName)
FileIO.FileSystem.MoveFile(oSourceFileName, oDestinationFileName)

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 5

MTheDesigner
Advocate
Advocate

Hi, @WCrihfield Thanks for replying.

 

I think I may not have been clear enough.

 

I don't mean move files around folders in the file explorer (although I didn't know you could do that and it is very useful to know).

 

I mean move parts around in the model browser.

For example the code 

ThisAssembly.BeginManage("Group1")

is referencing a folder that is in the file tree.

0 Likes
Message 4 of 5

WCrihfield
Mentor
Mentor
Accepted solution

OK.  I think I understand now.  You want to know how to move assembly components in the model browser tree into and out of a model tree browser folder by code.  Well...moving things around in the model browser tree is sometimes rather tricky, but if it can be done manually, you can likely do it by code.  I opened up one of my testing assemblies and created a fairly basic iLogic rule to do a task like this.  I don't know if you want the code to create this specifically named browser folder if it is not already found or not.  It will let you have multiple browser folders with the same name, so that can be tricky too.  Also, when you create a browser folder by code, you have the option to immediately put one or more browser nodes into that folder when you create it.  Or you can just create the empty folder, then put stuff into it later.  This example first looks for the folder, and if not found at the top level of the tree structure, it will create it.  Then it gets a few specific top level components by name that I want to put into the folder.  Then it gets the browser nodes for those components.  Then it puts those browser nodes into the browser folder.

Of course, if you want to test this out, you would most likely need to change the names of the components, or get the components a different way.

Dim oADoc As AssemblyDocument = ThisDoc.Document
oADef = oADoc.ComponentDefinition
oOccs = oADef.Occurrences
oModelPane = oADoc.BrowserPanes.Item("Model")
'oModelPane = oADoc.BrowserPanes.Item("AmBrowserArrangement") 'using InternalName
oTopNode = oModelPane.TopNode
Dim oGroup1Folder As BrowserFolder = Nothing
For Each oFolder As BrowserFolder In oTopNode.BrowserFolders
	If oFolder.Name = "Group1" Then
		oGroup1Folder = oFolder
		Exit For
	End If
Next
If IsNothing(oGroup1Folder) Then
	oGroup1Folder = oModelPane.AddBrowserFolder("Group1")
End If
oOcc1 = oOccs.ItemByName("Part1:3")
oOcc2 = oOccs.ItemByName("Part1:4")
oOcc3 = oOccs.ItemByName("Part3:3")
oNode1 = oModelPane.GetBrowserNodeFromObject(oOcc1)
oNode2 = oModelPane.GetBrowserNodeFromObject(oOcc2)
oNode3 = oModelPane.GetBrowserNodeFromObject(oOcc3)
oGroup1Folder.Add(oNode1)
oGroup1Folder.Add(oNode2)
oGroup1Folder.Add(oNode3)

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 5

MTheDesigner
Advocate
Advocate

Hey @WCrihfield, Thanks for helping to illuminate the subject for me. I was completely unaware of how to access the browser tree and the term node didn't even come to mind. Between your current code and the new keywords I know to search for, you have solved my problems. You are the real MVP.

0 Likes