By Adam Nagy
When you use an Asset, whether it's Material or Appearance, it gets copied into the document and can be accessed from the following properties of the Document object:
- AppearanceAssets
- MaterialAssets
- Assets (both Appearances and Materials)
If you want to get rid of unused items (i.e. purge the assets collection in the document) then you can just iterate through the items in the collections and remove the unused ones (where IsUsed = False).
Note: there might be connections between the assets in which case you have to iterate through them multiple times, until all the items stay used.
Sub PurgeMaterialsAndAppearances() Dim doc As PartDocument Set doc = ThisApplication.ActiveDocument ' There can be references between assets, ' so keep doing it until only used things remain Dim foundUnused As Boolean Do foundUnused = False Dim a As Asset For Each a In doc.Assets If Not a.IsUsed Then a.Delete foundUnused = True End If Next Loop While foundUnused End Sub
This is what we start off with in the document and what we end up with after running the above code: