Delete suppressed components

<?xml encoding=”UTF-8″>By Adam Nagy

You may want to make the current LOD the master LOD in the assembly in which case you can delete the suppressed components in the assembly. Once I run the below VBA code the Master LOD of MainAsm document will not contain the components suppressed in LevelOfDetail1 LOD so basically the content of Master LOD and LevelOfDetail1 LOD will be the same. 

Sub DeleteSuppressedComponent(occs As ComponentOccurrences)
Dim occ As ComponentOccurrence
For Each occ In occs
If occ.Suppressed Then
occ.Delete
Else
Call DeleteSuppressedComponent(occ.SubOccurrences)
End If
Next
End Sub
Sub DeleteSuppressedComponents()
Dim doc As AssemblyDocument
Set doc = ThisApplication.ActiveDocument
Dim acd As AssemblyComponentDefinition
Set acd = doc.ComponentDefinition
Call DeleteSuppressedComponent(acd.Occurrences)
End Sub

This is the result we’d get in case of the below assembly structure:

SuppressedComponents

 


Comments

7 responses to “Delete suppressed components”

  1. Kevin Jans Avatar
    Kevin Jans

    Hello Adam,
    I find the macro very helpfull but encounter a problem when running the macro in a main assembly which contains iParts and iAssemblies.
    My goal is to suppress the parts that are “Excluded” in an iAssembly. Run from the main assembly
    So in the macro itself i have changed
    If occ.Suppressed Then
    occ.Delete
    to
    If occ.Excluded Then
    occ.Suppress
    This works fine when is run from the iAssembly itself.
    But i need it to work form the main assembly file.
    Run time error:
    Method ‘SubOccurrences’ of object ‘ComponentOccurrenceProxy’ failed
    Thank you

  2. Hi Kevin,
    I’m not sure I understand how you get into that issue. Are you using the above code inside some other code? It seems to me that Occurrences and SubOccurrences do not include Excluded components in context of the main assembly.
    Best thing would be if you asked this question on the Inventor Customisation forum and provided non-confidential minimal sample documents, the exact code, the exact steps to reproduce the problem.
    Cheers,
    Adam

  3. This is super slow for large assemblies.
    Global transactions seem to help somewhat. My current theory is that this is due to excessive amounts of undo information (or something) stored on disk.

  4. Hi Johan,
    You could also try setting Application.AssemblyOptions.DeferUpdate and Application.ScreenUpdating as mentioned in Brian’s AU class: http://aucache.autodesk.com/au2012/sessionsFiles/3547/4363/handout_3547_CP3547-InventorAPIOddsAndEnds.pdf
    Cheers,
    Adam

  5. Can I run this code also in an Ilogic rule. Pasted it in and gave it a try but bad luck.

  6. Hi Adam,
    Thanks you so much :-)
    Putting the 2 samples next to each other is very educational for me.
    Learning a lot, I can see also that my attempts to modify the VBA to ilogic were almost correct upon the point I gave up :-).

Leave a Reply to Kevin JansCancel reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading