Purge unused materials and styles

Purge unused materials and styles

andrewiv
Advisor Advisor
1,290 Views
4 Replies
Message 1 of 5

Purge unused materials and styles

andrewiv
Advisor
Advisor

I'm looking to write an iLogic rule that will go through a document and purge all of the unused materials and styles.  Ideally I would like this to handle any type of document whether it be ipt, iam, or idw but if I have to write a separate rule for each I'm OK with that.

 

I've done some searching and not found anything that I can use yet.  I was wondering if anyone has figured this out yet?

Andrew In’t Veld
Designer / CAD Administrator

0 Likes
1,291 Views
4 Replies
Replies (4)
Message 2 of 5

MechMachineMan
Advisor
Advisor

Here's a starting point for you. Works on drawings. I don't imagine for parts and iams it would look very different.

 

			Sub PurgeStyles()
				
				Dim oStyles As DrawingStylesManager
				oStyles = oDoc.StylesManager
				
				Dim noneleft As Boolean
				noneleft = True
				
				Dim ostyle As Style
				
				Do While (noneleft)
					noneleft = False
					For Each ostyle In oStyles.Styles
						If (ostyle.StyleLocation = kLocalStyleLocation) And (ostyle.InUse = False) Then
							ostyle.Delete
							noneleft = True
						End If
					Next
				Loop
			End Sub

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 3 of 5

andrewiv
Advisor
Advisor

This did not work for me.  I did a simple test and started a new drawing, created a new balloon style and ran your code.  After running it the new balloon style is still there even though it isn't used anywhere.  When I manually go to the manage tab and hit the purge command, the new style shows up.

Andrew In’t Veld
Designer / CAD Administrator

0 Likes
Message 4 of 5

MechMachineMan
Advisor
Advisor

Ok?

 

Convert it to VBA, put it in the VBA environment in inventor, add a watch to break when true for when oStyle.Name = "your new balloon style name".

 

Step through the code after that point, see what flags its skipping/tripping. 

 

Modify it from there.


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 5 of 5

james.collinsPWQR2
Advocate
Advocate

Try this:

Dim oDoc As DrawingDocument = ThisApplication.ActiveEditDocument
Dim oStyles As DrawingStylesManager = oDoc.StylesManager
Dim noneleft As Boolean = True
Dim ostyle As Style
Do While (noneleft)
	noneleft = False
	For Each ostyle In oStyles.Styles
		If ostyle.StyleLocation = 51202 And ostyle.InUse = False Then
			' uncomment next line to see styles being deleted
'			MsgBox(ostyle.Name)
			ostyle.Delete
			noneleft = True
		End If
	Next
Loop

 
Cheers,
James

0 Likes