How to get an array of 3dPoints from given Polyline object in GHPython

Guys, maybe it’s to hot today, but I currently cannot figure out how to get an array of 3DPoints from a Polyline object in GHPython.

I am sure it is EXTREMELY simple… but I am currently struggling. Can you quickly help me out?

I am searching for something like .CenterPoint() but as an array of all points of the Polyline.

Try this, maybe not the most optimized code but it should do

import Rhino.Geometry as rg

# Input curve as an Item Access Polyline
# Output a

pts = []

segments = curve.GetSegments().Count

for i in range(segments+1):
    pts.append(curve.PointAt(i))

a = pts
2 Likes

This is the same method as above

a = [curve.PointAt(i) for i in range(curve.SegmentCount+1)]
1 Like

@jordi.arcas and @Adam_M
Thank you both for your answers - that certainly works. :grinning:

However, I still wonder why there is nothing built in. I mean getting the points of a polyline seems like a standard task to me. So I was hoping that I just overlooked something.

It does seem like there should be a simpler way.

Using RhinoScriptSyntax you can do:

import rhinoscriptsyntax as rs

rs.CurveEditPoints(curve)

https://developer.rhino3d.com/api/RhinoScriptSyntax/#curve-CurveEditPoints

You can use the yourPolyline.ToArray() method. Or cast it using list(yourPolyline).

3 Likes

@AndersDeleuran Yes - that was the one that I overlooked. Works exactly like I expected - but just did not recognize it with that name.

Thanks a lot (marked your answer as the solution).

1 Like