iLogic – Delete all Mates/Joints & Ground

2018-10-01_08h56_30

Have you ever wanted to delete all of the constraints in an assembly, and then ground all components? Well look no further, the iLogic code in this blog post does exactly that.

You may be wondering why you would want to do this, well the answer is simple. Inventor calculates each relationship between parts (especially when adding or moving components). In a large static assembly (no moving parts), the file performance will improve, if all of the components are grounded, as opposed to having several constraints applied to them.

I put this code together based on some of the Autodesk Inventor API samples, as well as with some code borrowed from Curtis Waguespack’s blog post on unconstrained geometry. I’ve also updated the code to include assembly joints as well.

The animated GIF below, shows the code in action.

Autodesk Inventor ilogic - delete constraints joints and ground - clintbrown

'start of ilogic code
'Some code here was borrowed from Curtis, see http://inventortrenches.blogspot.com/2012/05/working-with-unconstrained-imported.html
'This version of the code was first published on ClintBrown.co.uk
'https://clintbrown.co.uk/ilogic-delete-all-mates-joints-ground

Dim oAssDoc As AssemblyDocument

oAssDoc = ThisApplication.ActiveDocument
Dim oConstraint As AssemblyConstraint
Dim oJoint As AssemblyJoint

CheckWithUser = MessageBox.Show("Are you sure you want to Delete All Constraints?","iLogic - ClintBrown3D",MessageBoxButtons.YesNo)

If CheckWithUser = vbNo Then
Return
Else
i = 0
For Each oConstraint In oAssDoc.ComponentDefinition.Constraints
oConstraint.Delete
i = i + 1
Next

ii = 0
For Each oJoint In oAssDoc.ComponentDefinition.Joints
oJoint.Delete
ii = ii + 1
Next

End If
MessageBox.Show(" A total of " & i & " constraints " & ii & " joints were deleted.", "iLogic - @ClintBrown3D")

qGround = True

'get the active assembly
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

'set the Master LOD active
Dim oLODRep As LevelOfDetailRepresentation
oLODRep = oAsmCompDef.RepresentationsManager.LevelOfDetailRepresentations.Item("Master")
oLODRep.Activate

'Iterate through all of the top level occurrences
Dim oOccurrence As ComponentOccurrence
For Each oOccurrence In oAsmCompDef.Occurrences
If oOccurrence.DefinitionDocumentType = _
DocumentTypeEnum.kAssemblyDocumentObject Then
'Iterate through all of the 2nd level occurrences
Dim oSub1Occ As ComponentOccurrence
For Each oSub1Occ In oOccurrence.SubOccurrences
'ground everything in the 2nd level
oSub1Occ.Grounded = qGround
If oSub1Occ.DefinitionDocumentType = _
DocumentTypeEnum.kAssemblyDocumentObject Then
'Iterate through all of the 3nd level occurrences
Dim oSub2Occ As ComponentOccurrence
For Each oSub2Occ In oSub1Occ.SubOccurrences
'ground everything in the 3rd level
oSub2Occ.Grounded = qGround
Next
Else
End If
Next
Else
End If
'ground everything in the top level
oOccurrence.Grounded = qGround

Next
MessageBox.Show(" All Parts have been Grounded", "iLogic - @ClintBrown3D")
' end of ilogic code

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.