Wednesday, January 23, 2013

iLogic: Delete All Sick Assembly Constraints

Issue:
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.



Solution:
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: http://www.blh.com.au/#/blog/4572268941             






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

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

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

Thursday, January 17, 2013

iLogic Solid Body Visibility



Issue:
You want to be able to control the visibility of Solid Bodies in a Multi Body part file using  your iLogic rule.




Solution:
Here is a quick example that demonstrates several options to toggle the visibility of solid bodies on and off.




'define the document as a component definition
Dim oCompDef as ComponentDefinition
oCompDef = ThisDoc.Document.ComponentDefinition

'define the solidbody
Dim oBody as SurfaceBody

'add each solid body name to a list
Dim MyArrayList As New ArrayList
i = 1
For Each SurfaceBody in oCompDef.SurfaceBodies
oBody = oCompDef.SurfaceBodies.Item(i)
MyArrayList.add(oBody.Name)
i = i +1
Next

'add Show and Hide all options to the list
MyArrayList.add(" *Show All")
MyArrayList.add(" *Hide All")

'present the user with the list and record the selection
sBody  = InputListBox("Select a Solid Body to Toggle Visibility.", _
MyArrayList, "", "iLogic", "List of Solid Bodies")

'toggle all on or all off, if those options were selected
If sBody = " *Show All" Then
          i = 1
          For Each SurfaceBody in oCompDef.SurfaceBodies
            oBody = oCompDef.SurfaceBodies.Item(i)
          oBody.Visible = True
            i = i +1
          Next
ElseIf sBody = " *Hide All"
            i = 1
          For Each SurfaceBody in oCompDef.SurfaceBodies
            oBody = oCompDef.SurfaceBodies.Item(i)
          oBody.Visible = False
            i = i +1
          Next
End If

'compare the user selection to the solid body names
'and toggle the visibility for the one the matches (if any)
i = 1
For Each SurfaceBody in oCompDef.SurfaceBodies
oBody = oCompDef.SurfaceBodies.Item(i)
If sBody = oBody.Name Then
          If oBody.Visible = False Then
          oBody.Visible = True
            Else
          oBody.Visible = False
            End If
End If
MyArrayList.add(oBody.Name)
i = i +1
Next