iLogic – Suppress/Unsuppress and Delete Parts

@ClintBrown3D Autodesk Inventor ilogic delete supress part

I wrote a blog post a few weeks back, talking about Suppressing/Unsuppressing & deleting iLogic rules, and I got asked on Reddit if this could be applied to Assemblies and Components too.

The short answer was yes, the tricky part was including some code to handle custom Levels of detail, which I’ve done in the code below (look under suppress:)

Here is an animated GIF of the iLogic code in action:

unofficial inventor - ilogic supress delete parts
Click me for higher res version

As this code allows users to DELETE components, please proceed with extreme caution!

Here is the iLogic code:

'iLogic Code by @ClintBrown3D
'Originally posted at https://clintbrown.co.uk/ilogic-suppress-unsuppress-and-delete-parts

Dim ClintBrown3D As New ArrayList

'Iterate Through the Assembly
Dim oDoc As Inventor.AssemblyDocument
oDoc = ThisApplication.ActiveDocument
Dim oCompDef As Inventor.ComponentDefinition
oCompDef = oDoc.ComponentDefinition
Dim oCompOcc As ComponentOccurrence
For Each oCompOcc In oCompDef.Occurrences
Next

d0 = InputListBox("What would you like to do?", {"Suppress Component","Unsuppress Component", "Delete Component"}, d0, Title := "@ClintBrown3D", ListName := "This Utility lets you Suppress/Unsuppress/Delete Components")
	If d0 = "Suppress Component" Then : GoTo Suppress : End If
	If d0 = "Unsuppress Component" Then : GoTo Unsuppress : End If
	If d0 = "Delete Component" Then : GoTo Delete : End If
	If d0 = "" Then : GoTo ClintsErrorTrap : End If

Suppress :
	For Each oCompOcc In oCompDef.Occurrences
	ClintBrown3D.Add(oCompOcc.Name)
	Next
	iLogicRules = InputListBox("Select A Component to suppress" , ClintBrown3D, d0, Title := "@ClintBrown3D: Suppress a Component", ListName := "Below is a list of Components in this Assembly")

	'Create and Set Custom LOD"
	Dim doc As AssemblyDocument = ThisDoc.Document
	Dim oLOD As LevelOfDetailRepresentation
	Dim oAsmCompDef As ComponentDefinition
	oAsmCompDef = doc.ComponentDefinition
	Try
	oLOD = oAsmCompDef.RepresentationsManager.LevelOfDetailRepresentations.Add("iLogic")
	Catch
	oLOD = oAsmCompDef.RepresentationsManager.LevelOfDetailRepresentations.Item("iLogic")
	oLOD.Activate(True)
	End Try
	Component.IsActive(iLogicRules) = False
	Return

Unsuppress :
	For Each oCompOcc In oCompDef.Occurrences
	ClintBrown3D.Add(oCompOcc.Name)
	Next
	iLogicRules1 = InputListBox("Select A Component to Unsuppress" , ClintBrown3D, d0, Title := "@ClintBrown3D", ListName := "Below is a list of Components in this Assembly")
	Component.IsActive(iLogicRules1) = True
	Return

Delete :
	For Each oCompOcc In oCompDef.Occurrences
	ClintBrown3D.Add(oCompOcc.Name)
	Next
		iLogicRules2 = InputListBox("Select A Component to Delete", ClintBrown3D, d0, Title := "@ClintBrown3D: Delete a Rule", ListName := "Below is a list of Components in this Assembly")
		i = MessageBox.Show("Are you sure that you want to permanently Delete **" & iLogicRules2 & " **", "DELETE " & iLogicRules2 ,MessageBoxButtons.YesNo)
	If i = vbYes Then : GoTo ClintBrown1 : Else : GoTo ClintsErrorTrap : End If

ClintBrown1 :
	Components.Delete(iLogicRules2)
	MessageBox.Show(iLogicRules2 & " Successfully Deleted" & vbNewLine & vbNewLine & "Hitting Undo may restore the Component", "@ClintBrown3D")
	Return

ClintsErrorTrap :

This version of the code was briefly tested with Inventor 2020.

Please note that I cannot offer any additional support, this blog post is offered as-is, and is aimed at the more advanced user.

As always, please test all iLogic code extensively on non-production files. Do not use any code in a production environment until YOU have thoroughly tested it and have verified that it works as expected. Always back up any data before running any experimental code. You are ultimately responsible for any iLogic code that you run, so make sure you test it thoroughly!

This site takes absolutely no responsibility for how you use this code in production (see disclaimer).