×
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

Does anybody know how to extract the coordinates for the points in a polyline?

Does anybody know how to extract the coordinates for the points in a polyline?

Does anybody know how to extract the coordinates for the points in a polyline?

(OP)
I'm trying to write a macro that can create a coordinate table for all the points making up a polyline. So far I've been able to export the coordinates of ordinary points to Excel.
However, polylines have proven difficult.
I found code for the polyline.getElement method, but how is the result stored? Array, variable...?

Dim HybShpPolylineElement As Reference
Dim HybShpPolylineRadius As Reference
HybShpPolyline.GetElement 1, HybShpPolylineElement,HybShpPolylineRadius

I'm a beginner when it comes to vba for Catia so I'm at a loss here.

RE: Does anybody know how to extract the coordinates for the points in a polyline?

(OP)
It's a 3D polyline, with ordinare 3D points, used for creating pipes and similar structures.
The problem is that I can't find out how the "GetElement" method should present the data when there are multiple variables in the method. Everything else works fine.
The goal is simply to create a table with coordinates and radiues for each point in the polyline.
Code below, problem area marked in red.

CODE --> CATscript

'variables
Dim objGEXCELapp As Object Dim objGEXCELwkBks As Object Dim objGEXCELwkBk As Object Dim objGEXCELwkShs As Object Dim objGEXCELSh As Object Dim coords(3) As Integer Sub CATMain()
'main sub
startExcel exportPolylinePoints End Sub '**************************************************************************** Sub StartEXCEL()
'function for opening excel
'**************************************************************************** Err.Clear On Error Resume Next Set objGEXCELapp = GetObject(, "EXCEL.Application") If Err.Number <> 0 Then Err.Clear Set objGEXCELapp = CreateObject("EXCEL.Application") End If objGEXCELapp.Application.Visible = True Set objGEXCELwkBks = objGEXCELapp.Application.WorkBooks Set objGEXCELwkBk = objGEXCELwkBks.add Set objGEXCELwkShs = objGEXCELwkBk.Worksheets(1) Set objGEXCELSh = objGEXCELwkBk.Sheets(1) objGEXCELSh.Cells(1, "A") = "ITEM X" objGEXCELSh.Cells(2, "A") = "POINT" objGEXCELSh.Cells(2, "B") = "X" objGEXCELSh.Cells(2, "C") = "Y" objGEXCELSh.Cells(2, "D") = "Z" objGEXCELSh.Cells(2, "E") = "RADIUS" End Sub
'*********************************************************** Sub exportPolylinePoints
'function for exporting the points
'*********************************************************** Dim selection1 As selection 'selection in Catia Set Selection1 = CATIA.ActiveDocument.selection 'pick first element (the polyline) of the selection in Catia Dim polyline1 As HybridShapePolyline Set polyline1 = selection1.Item(1).value 'get the number of elements in the polyline dim polyline1NrOfElements as long polyline1NrOfElements = polyline1.NumberOfElements MsgBox "The selected polyline has " & polyline1NrOfElements & " points." 'display number of elements for i = 1 to polyline1NrOfElements dim pointRef as reference dim pointRad as double polyline1.GetElement(i), pointRef, pointRad 'How is the result from GetElement presented? This is my problem. 'Write PointData to Excel Sheet objGEXCELSh.Cells(i + 2, "A") = pointRef.Name objGEXCELSh.Cells(i + 2, "B") = coordsArray(0) objGEXCELSh.Cells(i + 2, "C") = coordsArray(1) objGEXCELSh.Cells(i + 2, "D") = coordsArray(2) objGEXCELSh.Cells(i + 2, "E") = coordsArray(3) 'the radius objGEXCELSh.Cells(i + 3, "A") = "TOTAL LENGTH = " next end Sub

RE: Does anybody know how to extract the coordinates for the points in a polyline?

try this:

CODE --> vba

Dim pointRef As Reference
Dim pointRad  As Length
polyline1.GetElement i, pointRef, pointRad 


but you still have other errors

Eric N.
indocti discant et ament meminisse periti

RE: Does anybody know how to extract the coordinates for the points in a polyline?

I could not check everything (I have some VBA ref file conflict) but that should help:

CODE --> vba

'variables
Dim objGEXCELapp As Object
Dim objGEXCELwkBks As Object
Dim objGEXCELwkBk As Object
Dim objGEXCELwkShs As Object
Dim objGEXCELSh As Object
Dim coords(2) As Variant
Dim TheMeasurable As Variant
Dim TheSPAWorkbench As Workbench


Sub CATMain()

StartEXCEL
exportPolylinePoints
End Sub

'****************************************************************************
Sub StartEXCEL()
'function for opening excel
'****************************************************************************
Err.Clear
On Error Resume Next
Set objGEXCELapp = GetObject(, "EXCEL.Application")

If Err.Number <> 0 Then
Err.Clear
Set objGEXCELapp = CreateObject("EXCEL.Application")
End If

objGEXCELapp.Application.Visible = True
Set objGEXCELwkBks = objGEXCELapp.Application.WorkBooks
Set objGEXCELwkBk = objGEXCELwkBks.Add
Set objGEXCELwkShs = objGEXCELwkBk.Worksheets(1)
Set objGEXCELSh = objGEXCELwkBk.Sheets(1)
objGEXCELSh.Cells(1, "A") = "ITEM X"
objGEXCELSh.Cells(2, "A") = "POINT"
objGEXCELSh.Cells(2, "B") = "X"
objGEXCELSh.Cells(2, "C") = "Y"
objGEXCELSh.Cells(2, "D") = "Z"
objGEXCELSh.Cells(2, "E") = "RADIUS"

End Sub
'***********************************************************
Sub exportPolylinePoints()
'function for exporting the points
'***********************************************************
 Dim selection1 As Selection        'selection in Catia
    Set selection1 = CATIA.ActiveDocument.Selection
        
        'pick first element (the polyline) of the selection in Catia
        Dim polyline1 
        Set polyline1 = selection1.Item(1)
        Dim oPolyline As HybridShapePolyline
        Set oPolyline = polyline1.Value' Dont ask me why but I had to do that to get it to work properly
           
        
        'get the number of elements in the polyline
        Dim polyline1NrOfElements 'As Long
        polyline1NrOfElements = oPolyline.NumberOfElements
            MsgBox "The selected polyline has " & polyline1NrOfElements & " points."        'display number of elements
    
            For i = 1 To polyline1NrOfElements
                Dim pointRef As Reference
                Dim oRad  As Length
                oPolyline.GetElement i, pointRef, oRad
                
                Set TheSPAWorkbench = CATIA.ActiveDocument.GetWorkbench("SPAWorkbench") ' set TheSPAWorkbench
                Set TheMeasurable = TheSPAWorkbench.GetMeasurable(pointRef)             ' set Measurable with reference
                TheMeasurable.GetPoint coords                                           ' get coordinates from Measurable

                If oRad Is Nothing Then RadiusAtPoint = False Else RadiusAtPoint = True ' check if Radius at point


                 
'                Write PointData to Excel Sheet
                objGEXCELSh.Cells(i + 2, "A") = pointRef.DisplayName
                objGEXCELSh.Cells(i + 2, "B") = coords(0)
                objGEXCELSh.Cells(i + 2, "C") = coords(1)
                objGEXCELSh.Cells(i + 2, "D") = coords(2)
                If RadiusAtPoint then objGEXCELSh.Cells(i + 2, "E") = oRad.Value  'the radius
                objGEXCELSh.Cells(i + 3, "A") = "TOTAL LENGTH = "

            Next

End Sub 

Eric N.
indocti discant et ament meminisse periti

RE: Does anybody know how to extract the coordinates for the points in a polyline?

(OP)
Thanks alot!
This worked perfectly. I was even able to add length measurement of the polyline aswell.
Awsome, thanks.

Btw, does this forum have a "collection thread" for macros/ functions like this?
I guess alot of people could benefit from the soulutions that are created here.

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