josephv
Mechanical
- Oct 1, 2002
- 683
Hello,
We are having some issues selecting an edge via the API.
We wrote the macro below and it works well with lines, but an error occurs when we select edges.
In brief the macro below rotates a body around an axis and the angle of rotation is the angle between a selected line (the first element) an a selected edge (the second element).
SelectElement2 was used. Obviously we are missing something here, since a line works but an edge does not.
Thanks,
Joseph
Language="VBSCRIPT"
Sub CATMain()
Dim oPartDoc
Dim InputObjectType(0)
Dim oRef1
Dim referenceObject1
Dim oRef2
Dim referenceObject2
Set oPartDoc = CATIA.ActiveDocument.Part
Set Selection = CATIA.ActiveDocument.Selection
'We propose to the user that he select a line
InputObjectType(0)="Line"
Status=Selection.SelectElement2(InputObjectType,"Select a line",true)
Set oRef1 = Selection.Item(1).Value
Set referenceObject1 = oPartDoc.CreateReferenceFromGeometry(oRef1)
'We propose to the user that he select an edge
InputObjectType(0)="TriDimFeatEdge"
Status=Selection.SelectElement2(InputObjectType,"Select an edge",true)
Set oRef2 = Selection.Item(1).Value
Set referenceObject2 = oPartDoc.CreateReferenceFromGeometry(oRef2)
Set shapeFactory1 = oPartDoc.ShapeFactory
Set bodies1 =oPartDoc.Bodies
Set body1 = bodies1.Item("PartBody")
Set hybridShapes1 = body1.HybridShapes
Set hybridShapeLinePtPt1 = hybridShapes1.Item("Line.Axis")
Set reference1 = oPartDoc.CreateReferenceFromObject(hybridShapeLinePtPt1)
Set rotate1 = shapeFactory1.AddNewRotate2(reference1, 0.000000)
Set hybridShapeRotate1 = rotate1.HybridShape
hybridShapeRotate1.RotationType = 2
hybridShapeRotate1.Axis = reference1
hybridShapeRotate1.FirstElement = referenceObject1
'the line below causes an error
hybridShapeRotate1.SecondElement = referenceObject2
hybridShapeRotate1.OrientationOfFirstElement = False
hybridShapeRotate1.OrientationOfSecondElement = False
oPartDoc.InWorkObject = hybridShapeRotate1
oPartDoc.Update
End Sub