Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations KootK on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get the End Point coordinates of a selected 3D line 1

Status
Not open for further replies.

josephv

Mechanical
Oct 1, 2002
683

Hello,

Was wondering if anyone knew...

How to get the End Point coordinates of a selected 3D line

Using the CATIA API (i.e. Macros). We looked at the Infrastructure Help and could not find a way to do this.

Kind regards,

Joseph
 
Replies continue below

Recommended for you

Hi,

you can use :

TheMeasurable.GetPointsOnCurve (aCoordinates)

and get the first and last point coordonates from aCoordonates array...

Have a look on the online about :
TheSPAWorkbench.GetMeasurable(referenceObject)

Eric N.
indocti discant et ament meminisse periti
 
try this :

Sub CATMain()

Dim oPartDoc As Part
Dim TheSPAWorkbench As Workbench
Dim oRef As Line
Dim referenceObject As Reference
Dim TheMeasurable As Variant
Dim aCoordinates(8) As Variant
Dim oSel As Selection

Set oPartDoc = CATIA.ActiveDocument.Part
Set TheSPAWorkbench = CATIA.ActiveDocument.GetWorkbench("SPAWorkbench")
Set oSel = CATIA.ActiveDocument.Selection

On Error Resume Next

Set oRef = oSel.Item(1).Value

Set referenceObject = oPartDoc.CreateReferenceFromGeometry(oRef)
Set TheMeasurable = TheSPAWorkbench.GetMeasurable(referenceObject)

TheMeasurable.GetPointsOnCurve (aCoordinates)

If Err.Number = 0 Then
MsgBox "Start Point of line (" & oRef.Name & ")" & aCoordinates(0) / 25.4 & " ," & aCoordinates(1) / 25.4 & " ," & aCoordinates(2) / 25.4
MsgBox "End Point of line (" & oRef.Name & ")" & aCoordinates(6) / 25.4 & " ," & aCoordinates(7) / 25.4 & ", " & aCoordinates(8) / 25.4
End If

Err.Clear

End Sub


This work if you preselect in the tree, if you want to preselect in 3D you need to activate Feature Element Filter

Eric N.
indocti discant et ament meminisse periti
 

Hello itsmyjob,

First a real big thanks, this is very appreciated.

Sorry to bug you but for some reason when we run this macro we get the following error.

Scripting Error 1002
Expected End of Statement
Statement: Dim oPartDoc As Part

I've seen this before for some reason the "Dim" statements are causing errors, I am sure we are missing something obvious.

Please let me know if you have any thoughts on this.

Thanks again,

Joseph
 
Are your CATIA libraries correctly referenced in VBA ?

you can remove all as XXX in all dim lines the result will be the same.

Eric N.
indocti discant et ament meminisse periti
 
Hello itsmyjob,

Thank you very much, it works now (by removing all the as XXX). We'll look into referencing the CATIA libraries correctly.

Have a great weekend,

Joseph
 
Hello all,

One more question.

Is there any way to get the name of the points that were used to create a selected line (via the API)?

In other words if Point.1 and Point.2 where used to make Line.1. The user selects Line.1, then runs a macro that pops us "Point.1 and Point.2".

What we want to do is create a line that connects to the selected line, and this is why we need to know the names of the points.

Thanking you in advance,

Joseph

PS we looked into using PtExtremity and PtOrigine but not sure how they apply to a selected line
 
josephv,

Instead of looking in ptExtremity and PtOrigine look in parents. There should be 3 maybe more. Two of them will be points and the other one will be a hybridbody. You can search the parents for anything that is of type point and get the points that way.

Klogg
 
Hello itsmyjob and fellow users,

Thank you for your help.

question: how can one check that VBA correctly references the CATIA libraries?


Best regards,

Joseph
 

ok I got this one...

In VBA go to Tools > References and ensure all CATIA libraries are checked ON


Cheers,

Joseph
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor