08-05-2015
12:47 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
08-05-2015
12:47 PM
Hi dtowngurl51,
Here is a modification of the code you provided. This example simply names the new constraints as they are created, then you could use the code at this link to delete the constraints by name.
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
' Get references to the two occurrences to constrain.
' This arbitrarily gets the first and second occurrence.
Dim oOcc1 As ComponentOccurrence
oOcc1 = oAsmCompDef.Occurrences.Item(1)
Dim oOcc2 As ComponentOccurrence
oOcc2 = oAsmCompDef.Occurrences.Item(2)
' Get the work points from each occurrence. This goes to the
' component definition of the part to get this information.
' This is the same as accessing the part document directly.
' The work point obtained is in the context of the part,
' not the assembly.
Dim oPartPoint1 As WorkPoint
oPartPoint1 = oOcc1.Definition.WorkPoints.Item(1)
Dim oPartPoint2 As WorkPoint
oPartPoint2 = oOcc2.Definition.WorkPoints.Item(1)
Dim oPartPlaneXY As WorkPlane
oPartPlaneXY = oOcc1.Definition.WorkPlanes(3)
Dim oPart2PlaneXY As WorkPlane
oPart2PlaneXY = oOcc2.Definition.WorkPlanes(3)
' Because we need the work point in the context of the assembly
' we need to create proxies for the work points. The proxies
' represent the work points in the context of the assembly.
Dim oAsmPoint1 As WorkPointProxy
Call oOcc1.CreateGeometryProxy(oPartPoint1, oAsmPoint1)
Dim oAsmPoint2 As WorkPointProxy
Call oOcc2.CreateGeometryProxy(oPartPoint2, oAsmPoint2)
Dim oPartPlane1 As WorkPlaneProxy
Call oOcc1.CreateGeometryProxy(oPartPlaneXY, oPartPlane1)
Dim oPart2Plane1 As WorkPlaneProxy
Call oOcc2.CreateGeometryProxy(oPart2PlaneXY, oPart2Plane1)
'Create the constraint using the work point proxies.
Dim oConstraint As MateConstraint
oConstraint = oAsmCompDef.Constraints.AddMateConstraint(oAsmPoint1, oAsmPoint2, 0.5)
'name the constraint
oConstraint.Name = "MyConstraint1"
oConstraint = oAsmCompDef.Constraints.AddMateConstraint(oPartPlane1, oPart2Plane1, 0.5)
'name the constraint
oConstraint.Name = "MyConstraint2"