Using iLogic to delete all empty browser folders

Using iLogic to delete all empty browser folders

Anonymous
Not applicable
1,844 Views
8 Replies
Message 1 of 9

Using iLogic to delete all empty browser folders

Anonymous
Not applicable
I am trying to find some code which will check each of the browser folders in my structure and delete them if they are empty. Can anybody help please. Thank you in advance
0 Likes
Accepted solutions (1)
1,845 Views
8 Replies
Replies (8)
Message 2 of 9

Curtis_Waguespack
Consultant
Consultant
Accepted solution

Hi Skwiggle,

 

Here is a quick iLogic example rule.

 

 

oDoc = ThisDoc.Document
oPane = oDoc.BrowserPanes("Model")
oTopNode = oPane.TopNode

'Iterate through the browser folders
For Each oFolder in oTopNode.BrowserFolders
	i = 0
	'Iterate through the nodes in the folder
	oFolderNodes = oFolder.BrowserNode.BrowserNodes
	For Each oNode As BrowserNode In oFolderNodes
	'count the nodes
	i = i+1
	Next
	'delete the folder if the count = 0
	If i = 0 Then
	oFolder.Delete
	Else
	End If
Next

 I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

EESignature

Message 3 of 9

Anonymous
Not applicable

Hi Curtis, Thank you for you fast response, I tried the code but I get the following error:-

 

Rule Compile Errors in Rule1, in Assembly1

Cannot execute a program. The command being executed was "C:\Windows\Microsoft.NET\Framework64\v3.5\vbc.exe" /noconfig @"C:\Users\Damian\AppData\Local\Temp\cjuwy4xv.cmdline".

 

Any Ideas?

 

Thanks Regards

 

Damian

0 Likes
Message 4 of 9

salariua
Mentor
Mentor

I have just tested Curtis's code and it's working fine. What Inventor version are you on?

Adrian S.
blog.ads-sol.com 

AIP2012-2020 i7 6700k AMD R9 370
Did you find this reply helpful ?
If so please use the Accepted Solutions or Like button - Thank you!
0 Likes
Message 5 of 9

Anonymous
Not applicable

Just tried that code on a new assembly and it worked fine. Thanks for a great solution.

 

Damian

0 Likes
Message 6 of 9

andrew_canfield
Collaborator
Collaborator

Hello

 

Can this code be tweaked to suppress all folders called 'Reference' - ideally iterating though all sub assemblies?

 

Regards

 

Andrew

0 Likes
Message 7 of 9

Saqib.Iqbal
Enthusiast
Enthusiast

This doesnt delete empty folder within a folder. 

0 Likes
Message 8 of 9

Saloum_Diawara
Explorer
Explorer

Here the same code than Curtis, just a little bit more "compact"

   For Each oFolder As BrowserFolder In ThisApplication.ActiveDocument.BrowserPanes("Modell").TopNode.BrowserFolders
   If oFolder.BrowserNode.BrowserNodes.Count = 0 Then oFolder.Delete()
        Next

 

Message 9 of 9

WCrihfield
Mentor
Mentor

Since this old post resurfaced again, I decided to look into some of the concerns mentioned, such as being able to delete empty sub folders.  This sounded like a good task for a 'recursive' routine, and sounded like it should be easy to accomplish, so I decided to give it a try.  I was wrong...it was fairly difficult to accomplish, because upper level folders would not be deleted until lower level folders were deleted, which always left behind the empty top level folders...until I ran the process a second time at the end.  It ended up being a much larger code than I had originally anticipated though.  I attached the code in a text file, and hope it will help some folks out.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)