Wednesday, January 23, 2013

iLogic: Delete All Sick Assembly Constraints

You sometimes end up with a large number of broken (sick) assembly constraints, due to a particular workflow (such as swapping out a base component). You know why this is happening and don't mind fixing the assembly, but you wish there was a way to delete all of the sick assembly constraints at once, so you can re-constrain the assembly without having to be bothered by the alerts.

Here is a quick iLogic snippet to help with this:

* A special thanks to Brendan Henderson for letting me know about a coding error I had when I first posted this. Check out Brendan's own blog at:             

Dim oAssDoc As AssemblyDocument
oAssDoc = ThisApplication.ActiveDocument
Dim oConstraint As AssemblyConstraint

RUSure = MessageBox.Show _
("Are you sure you want to Delete all sick constraints?",  _

If RUSure = vbNo Then
          i = 0
          For Each oConstraint In oAssDoc.ComponentDefinition.Constraints
            If oConstraint.HealthStatus <> oConstraint.HealthStatus.kUpToDateHealth And _
            oConstraint.HealthStatus <> oConstraint.HealthStatus.kSuppressedHealth Then
            i = i + 1
          End If
End If
MessageBox.Show(" A total of "&  i & " constraints were deleted.", "iLogic")