How to get the End Point coordinates of a selected 3D line
How to get the End Point coordinates of a selected 3D line
(OP)
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





RE: How to get the End Point coordinates of a selected 3D line
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)
indocti discant et ament meminisse periti
RE: How to get the End Point coordinates of a selected 3D line
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
indocti discant et ament meminisse periti
RE: How to get the End Point coordinates of a selected 3D line
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
RE: How to get the End Point coordinates of a selected 3D line
you can remove all as XXX in all dim lines the result will be the same.
indocti discant et ament meminisse periti
RE: How to get the End Point coordinates of a selected 3D line
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
RE: How to get the End Point coordinates of a selected 3D line
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
RE: How to get the End Point coordinates of a selected 3D line
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
RE: How to get the End Point coordinates of a selected 3D line
Thank you for your help.
question: how can one check that VBA correctly references the CATIA libraries?
Best regards,
Joseph
RE: How to get the End Point coordinates of a selected 3D line
ok I got this one...
In VBA go to Tools > References and ensure all CATIA libraries are checked ON
Cheers,
Joseph