Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Using iLogic to delete all empty browser folders

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
Skwiggle
1318 Views, 8 Replies

Using iLogic to delete all empty browser folders

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
8 REPLIES 8
Message 2 of 9

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

Message 3 of 9

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

Message 4 of 9
salariua
in reply to: Skwiggle

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!
Message 5 of 9
Skwiggle
in reply to: Skwiggle

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

 

Damian

Message 6 of 9

Hello

 

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

 

Regards

 

Andrew

Message 7 of 9

This doesnt delete empty folder within a folder. 

Message 8 of 9
Saloum_Diawara
in reply to: Skwiggle

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
in reply to: Skwiggle

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report