PolyCurve By Points Python Script

I am trying to utilize a simple python script to perform the poly curve by points node in a controlled manner. Essentially taking points 0 and 1, make a line, take point 1 and 2, make line…

I am getting an error that I am having difficulty understanding:
“expected enumerable[point], got point”

Any idea what this means? I’ve googled enumerable point and got little hits on what that is. Do I have to enumerate “value” in the snip of the python code and then send it to the for loop?

This enumerate function is still quite foreign to me and I am not quite sure when I would use it.

Thanks!

PolyCurve.ByPoints takes two arguments, first one is Point[], second is a bool.

The first input, Point[] has the [] which means that you need a single level list of points, so that it can go one by one through them (i.e. enumerable). In your script, you called the command using two single point inputs, when it should be a list. To do what you want, replace the inside of .ByPoints() with:

.ByPoints(value[a:a+2],False)

This will give you individual sequential polycurves. The a+2 is because ranges specified with start:end does not include the end index.

If you want to keep the same order you had (where a+1 is the start, and a is the end), the notation would be different.

1 Like

Thanks @kennyb6, makes perfect sense.

Dear everyone,
I have some issues with this script node. I tried to use the @kennyb6 instructions and everything goes right. but my problem is that I have to manage not a single level list of points (2 level) and that I would like to close the poly. Actually without any success. Do you have any idea? Thank you very much
ELisabetta

@Elisabetta_Caterina Try this:

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

list = IN[0]
polycurves = []

for points in list:
	polycurves.append(PolyCurve.ByPoints(points,True))

OUT = polycurves
1 Like

thank you very much! actually, your method works fine with just one list of my points.
But for others, it doesn’t works.
the method to create polycurve by numbered elements worked better, but anyway the one suggested by @kennyb6 don’t close my polycurve.
Any other suggestion? thanks :slight_smile:
Elisabetta

To close the polycurve, the bool at the end would be True instead of False.
Besides that, to make it work on the second level, you just have to iterate the same function through each sublist. That means adding another for loop.

valList = IN[0]
fullpoly = []
for value in valList:
	temp = []
	for a in range(0, len(value)-1):
		temp.append(PolyCurve.ByPoints(value[a:a+2],True))
	fullpoly.append(temp)

OUT = fullpoly

This only works with a list level of two, if the list level varies, you will need recursion or flatten. If it is more than 2, you will have to add more for loops.

1 Like