Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

ilogic creating folders

mcgyvr
Consultant

ilogic creating folders

mcgyvr
Consultant
Consultant

Need a bit of help here.. 

I fumbled my way through creating this ilogic rule and some how I got lucky and it works .. 

 

But I'm stuck on how to modify this to check if the folder is already there and only create it if its not..

 

Thanks

 

Dim oDoc As Document 
oDoc = ThisApplication.ActiveDocument
Dim oPane As BrowserPane
oPane = oDoc.BrowserPanes("Model")
Dim oTopNode As BrowserNode
oTopNode = oPane.TopNode
Dim oFolder As BrowserFolder

Dim MyArrayList As New ArrayList
MyArrayList.add("ENCLOSURE")
MyArrayList.add("FASTENERS")
MyArrayList.add("LIGHTPIPES")
MyArrayList.add("DESIGNATION")
MyArrayList.add("PCB ASSYS")
MyArrayList.add("KITS")
MyArrayList.add("PACKAGING")
MyArrayList.add("REFERENCE")

For Each oval in MyArrayList
oFolder = oPane.AddBrowserFolder(oval)
Next

 

 



-------------------------------------------------------------------------------------------
Inventor 2023 - Dell Precision 5570

Did you find this reply helpful ? If so please use the Accept Solution button below.
Maybe buy me a beer through Venmo @mcgyvr1269
0 Likes
Reply
Accepted solutions (1)
3,629 Views
10 Replies
Replies (10)

Owner2229
Advisor
Advisor
Accepted solution

Hi, how about this?

 

Dim oDoc As Document = ThisApplication.ActiveDocument
Dim oPane As BrowserPane = oDoc.BrowserPanes.ActivePane
Dim oTopNode As BrowserNode = oPane.TopNode
Dim oFolder As BrowserFolder

Dim MyArrayList As New ArrayList
MyArrayList.add("ENCLOSURE")
MyArrayList.add("FASTENERS")
MyArrayList.add("LIGHTPIPES")
MyArrayList.add("DESIGNATION")
MyArrayList.add("PCB ASSYS")
MyArrayList.add("KITS")
MyArrayList.add("PACKAGING")
MyArrayList.add("REFERENCE")

For Each oVal In MyArrayList
    Try
	    oFolder = oTopNode.BrowserFolders.Item(oVal)
    Catch
        oFolder = oPane.AddBrowserFolder(oVal)
    End Try
Next
Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods

mcgyvr
Consultant
Consultant

Works perfect... So simple too thanks..

 



-------------------------------------------------------------------------------------------
Inventor 2023 - Dell Precision 5570

Did you find this reply helpful ? If so please use the Accept Solution button below.
Maybe buy me a beer through Venmo @mcgyvr1269
0 Likes

marcin_bargiel
Advocate
Advocate

How can I move parts to specific folders by iLogic code ?

Vote for REPLACE VARIES !
REPLACE VARIES
0 Likes

s.hofsteenge
Participant
Participant

is there a way to create subfolders in folders also? 

@Owner2229 

0 Likes

s.hofsteenge
Participant
Participant

is there a way to create subfolders also? 

0 Likes

WCrihfield
Mentor
Mentor

Hi @s.hofsteenge.  There is not a direct way to create a new browser folder within an existing browser folder, but I believe we can move one there by code, if conditions are right.  We can create the folder that we want to be a sub folder at the same (top) level as the other folders, then I think we can move the new folder down into another folder.  This would be done using the BrowserFolder.Add method.  That method allows us to move a BrowserNode into the existing folder.  That BrowserNode can be from the BrowserFolder.BrowserNode property of the new BrowserFolder.  That method may only work to move an empty folder though.  I do not know if it would let you move a folder that already has some stuff in it, down under another folder.  It may depend on the natural order of the objects within the folders. 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes

s.hofsteenge
Participant
Participant

@WCrihfield 

 

i cant figure it out... 

this is the code ive got sofar and this works great!

 

now i want to move folders:

kb klant specifiek

spb-oph klant specifiek

db-strip klantspecifiek

 

to folder: 

20.1 Snij-zetwerk

 

can you help me getting started? 

 

Dim oDoc As Document = ThisApplication.ActiveDocument
Dim oPane As BrowserPane = oDoc.BrowserPanes.ActivePane
Dim oTopNode As BrowserNode = oPane.TopNode
Dim oFolder As BrowserFolder

Dim MyArrayList As New ArrayList
MyArrayList.Add("10 Hulpframe")
MyArrayList.Add("20 Laadbak")
MyArrayList.Add("20.1 Snij-zetwerk")
MyArrayList.Add("kb klant specifiek")
MyArrayList.Add("spb-oph klant specifiek")
MyArrayList.Add("db-strip klantspecifiek")
MyArrayList.Add("20.2 Zaagwerk")
MyArrayList.Add("20.3 Kluytmans standaard delen")
MyArrayList.Add("db")
MyArrayList.Add("ITL-GSM")
MyArrayList.Add("spb-oph")
MyArrayList.Add("Beugel wl + zijmarkeerlamp")
MyArrayList.Add("20.4 inkoopdelen")
MyArrayList.Add("werklampen")
MyArrayList.Add("bindogen")
MyArrayList.Add("21 Kopschot")

For Each oVal In MyArrayList
    Try
	    oFolder = oTopNode.BrowserFolders.Item(oVal)
    Catch
        oFolder = oPane.AddBrowserFolder(oVal)
    End Try
Next

 

 

0 Likes

WCrihfield
Mentor
Mentor

Hi @s.hofsteenge.  Here is your code that I have modified a bit in a few places, and includes the extra code for moving those 3 folders over under the one folder, as you mentioned.  I also switched from using an ArrayList type collection to using a List(Of String) type collection, because it is more accurate for what we need here (a list of String values, not just a generic collection for any object type).   I also used a bit more code to make sure we are working with the true model browser pane, not one of the other ones.  

Dim oDoc As Document = ThisApplication.ActiveDocument
Dim oPanes As BrowserPanes = oDoc.BrowserPanes
Dim oModelPane As BrowserPane = Nothing
For Each oBP As BrowserPane In oPanes
	If oBP.BuiltIn And oBP.TreeBrowser And _
		(oBP.InternalName = "AmBrowserArrangement" Or _
		oBP.InternalName = "DlHierarchy" Or _
		oBP.InternalName = "PmDefault") Then
		oModelPane = oBP
	End If
Next
Dim oTopNode As BrowserNode = oModelPane.TopNode

Dim FolderNames As New List(Of String)
FolderNames.Add("10 Hulpframe")
FolderNames.Add("20 Laadbak")
FolderNames.Add("20.1 Snij-zetwerk") 'move them under this folder
FolderNames.Add("kb klant specifiek") 'move to sub folder
FolderNames.Add("spb-oph klant specifiek") 'move to sub folder
FolderNames.Add("db-strip klantspecifiek") 'move to sub folder
FolderNames.Add("20.2 Zaagwerk")
FolderNames.Add("20.3 Kluytmans standaard delen")
FolderNames.Add("db")
FolderNames.Add("ITL-GSM")
FolderNames.Add("spb-oph")
FolderNames.Add("Beugel wl + zijmarkeerlamp")
FolderNames.Add("20.4 inkoopdelen")
FolderNames.Add("werklampen")
FolderNames.Add("bindogen")
FolderNames.Add("21 Kopschot")

Dim oFolder As BrowserFolder
For Each sFolderName In FolderNames
    Try
	    oFolder = oTopNode.BrowserFolders.Item(sFolderName)
    Catch
        oFolder = oModelPane.AddBrowserFolder(sFolderName)
    End Try
Next

Dim oParentFolder As BrowserFolder = oTopNode.BrowserFolders.Item("20.1 Snij-zetwerk")
oParentFolder.AllowAddRemove = True
oParentFolder.AllowReorder = True
oParentFolder.AllowRename = True
'oParentFolder.AllowDelete = True
Dim oChildFolder1 As BrowserFolder = oTopNode.BrowserFolders.Item("kb klant specifiek")
Dim oChildFolder2 As BrowserFolder = oTopNode.BrowserFolders.Item("spb-oph klant specifiek")
Dim oChildFolder3 As BrowserFolder = oTopNode.BrowserFolders.Item("db-strip klantspecifiek")
oParentFolder.Add(oChildFolder1.BrowserNode)
oParentFolder.Add(oChildFolder2.BrowserNode)
oParentFolder.Add(oChildFolder3.BrowserNode)

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

HogueOne
Enthusiast
Enthusiast

What is the syntax for putting a component inside a folder we've created?

0 Likes

Curtis_Waguespack
Consultant
Consultant