×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Selecting an Edge via the API

Selecting an Edge via the API

Selecting an Edge via the API

(OP)

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

RE: Selecting an Edge via the API

(OP)
Ok fixed the problem. We were missing..

Selection.Clear

Have another question, but will post a new thread for it, since it is different.

Thanks,

Joseph

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources