Message 1 of 16

Not applicable
12-11-2019
04:32 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello fellow Inventor users, 😀
I was looking for a way to purge the styles of all the files I work with.
I couldn't find a finished code, so I started tinkering.
I came up with the following:
Dim oThisDoc As Document oThisDoc = ThisDoc.Document DocType = oThisDoc.DocumentType Select Case DocType.ToString '---File is a Drawing--- Case "kDrawingDocumentObject" Dim oDoc As DrawingDocument oDoc = ThisDrawing.Document Dim oStyles As Styles oStyles = oDoc.StylesManager.Styles ' Info: StyleLocation ' 51201 = both (library and local) ' 51202 = local ' 51203 = library DelStyles = True DelLoops = 0 While DelStyles = True And DelLoops < 100 DelCounter = 0 For Each oStyle In oStyles ' Only delete unused styles saved in 'local' or 'both' If oStyle.StyleLocation.ToString <> "51203" And Not oStyle.InUse Then oStyle.Delete DelCounter += 1 End If Next If DelCounter = 0 Then DelStyles = False DelLoops += 1 End While ' ---File is a part or assembly--- Case "kPartDocumentObject", "kAssemblyDocumentObject" Dim oStylesMan As StylesManager oStylesMan = ThisApplication.StylesManager Dim oDoc As Document oDoc = ThisApplication.ActiveDocument Dim oAsset As Asset ' Info: AssetType ' 99073 = appearances ' 99074 = materials ' Materials first For Each oAsset In oDoc.Assets If oAsset.AssetType = 99074 And Not oAsset.IsUsed Then oAsset.Delete End If Next ' Then appearances For Each oAsset In oDoc.Assets If oAsset.AssetType = 99073 And Not oAsset.IsUsed Then oAsset.Delete End If Next End Select
The code works flawlessly for drawings, but in parts or assemblies I always get an error, saying the active file is not a drawing.
Can someone figure out my mistake?
Many thanks in advance 😀
Solved! Go to Solution.