- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello!
When I'm making one type of assembly, I need to constrain many parts to the Z axis after placing them. So, I was able to compose some small code to do this task.
'Select the main assembly Z axis
'Set a reference to the assembly component definintion.
Dim oACD As AssemblyComponentDefinition
oACD = ThisApplication.ActiveDocument.ComponentDefinition
'Get the Z Axis of the assembly
Dim oZAxis1 As WorkAxis
oZAxis1 = oACD.WorkAxes.Item("Z Axis")
'Select the part Z axis
'Checking parts
Dim oZAxis2 As WorkAxis
Dim oOcc As ComponentOccurrence
Dim ozProxy As WorkAxisProxy
For Each oOcc In oACD.Occurrences
'Get the Z axis from the part
oZAxis2 = oOcc.Definition.WorkAxes.Item("Z Axis")
Call oOcc.CreateGeometryProxy(oZAxis2,ozProxy)
oACD.Constraints.AddMateConstraint(oZAxis1, ozProxy, 0)
Next
If I place 100 of these parts and I run the code, it works - every part has its own constraint to the Z axis of assembly. That's a total of 100 constraints on the Z axis.
But if I place just one part after these 100 and run the same code again, every one of those 100 gets another constraint to the Z axis, so the same constraint is multiplying for already constrained parts.
Is there maybe some way to prevent this from happening?
Solved! Go to Solution.