×
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

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

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

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

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

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

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

(OP)

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

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

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

(OP)
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

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

(OP)
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

RE: How to get the End Point coordinates of a selected 3D 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

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

(OP)
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

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

(OP)

ok I got this one...

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


Cheers,

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