Polyline output wanted but got a list of points

Hi all, I’m still new to grasshopper and I ran into this problem I cannot comprehend.

What I was trying to do was dead simple: create a polyline from a list of 3d points. Inside the Script Editor I seem to have got a polyline object (see screenshot), but the python comonent output gives me a list of 3 point, not a polyline. The preview in Rhino is also just 3 separate points.

I can’t seem to create a NURBS curve either…

Thanks in advance!

You probably want the PolylineCurve class, alternatively call the ToNurbsCurve() method on the Polyline. The reason a single Polyline will output as a list of points, is that it is essentially what it is (it inherits from the Point3D list class) and the GHPython component will see it as an iterable and try to get/output its values (ie the points).

Anders is correct.

I know a remedy.


This creates a tuple that capsulates the polyline. Grasshopper(or maybe Python) will see it as a list with one single item, so you will get the polyline as a single item.
The reason to put “,” at the end is that because (a) is ambiguous (can be either a tuple with a single item or simply a), Python syntax determines that, to create a single item tuple, you need to put , at the end.

That’s also pretty cool. Thanks so much!

I tend to call the ToNurbsCurve() myself, as it is quite explicit to anyone reading the code. Generally speaking though I rarely output a single polyline, and lists of polylines will output as expected as you point out :slight_smile: