Message 1 of 4
Adding contraints with VBA
Not applicable
07-23-2003
01:56 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have an assembly that contains multiple parts. I have been successful at adding parts with VBA code, but want to place constraints (mate and flush) on the parts I add. I created work planes specifically for this task in each of the parts I want to constrain. If I mate Work PlaneX in Part1 to Work PlaneZ in Part2, I will have exactly what I'm looking for. Below is the VBA code I have been using to try this. The code references specific Part Documents and Work Planes. These are working properly (referencing the correct parts and documents). The constraint call is the only thing not working. Am I on the right track?
TIA,
Chris Gitzlaff
Code:
Dim oAsmCompDef As AssemblyComponentDefinition
Set oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
Dim oPt1CompDef As PartComponentDefinition
Dim oPt2CompDef As PartComponentDefinition
Dim oMate As MateConstraint
Dim oWPlane1 As WorkPlane
Dim oWPlane2 As WorkPlane
Set oPt1CompDef = ThisApplication.Documents.Item(3).ComponentDefinition
Set oWPlane1 = oPt1CompDef.WorkPlanes.Item(9)
Set oPt2CompDef = ThisApplication.Documents.Item(6).ComponentDefinition
Set oWPlane2 = oPt2CompDef.WorkPlanes.Item(4)
Set oMate = oAsmCompDef.Constraints.AddMateConstraint(oWPlane1, oWPlane2, 0, kInferredLine, kInferredLine)
TIA,
Chris Gitzlaff
Code:
Dim oAsmCompDef As AssemblyComponentDefinition
Set oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
Dim oPt1CompDef As PartComponentDefinition
Dim oPt2CompDef As PartComponentDefinition
Dim oMate As MateConstraint
Dim oWPlane1 As WorkPlane
Dim oWPlane2 As WorkPlane
Set oPt1CompDef = ThisApplication.Documents.Item(3).ComponentDefinition
Set oWPlane1 = oPt1CompDef.WorkPlanes.Item(9)
Set oPt2CompDef = ThisApplication.Documents.Item(6).ComponentDefinition
Set oWPlane2 = oPt2CompDef.WorkPlanes.Item(4)
Set oMate = oAsmCompDef.Constraints.AddMateConstraint(oWPlane1, oWPlane2, 0, kInferredLine, kInferredLine)