I am learning how to write code in GHPython.
I am trying to iterate over a data tree collecting curves, find periodic curves, close them within the tree, return the tree with all closed curves.
As a workaround you could loop directly over the tree without converting it, like so:
import rhinoscriptsyntax as rs
a = []
for i, branch in enumerate(crv.Branches):
for j, item in enumerate(branch):
if rs.IsCurveClosed(item):
bool = "closed"
a.append(item)
else:
bool = "periodic"
pts = list(rs.CurveEditPoints(item))
pts.append(pts[0])
a.append(rs.AddInterpCurve(pts,1,2))
Note, that you have to set typehint to ghdoc if you want to use rhinoscriptsyntax!
Original code works with these changes (and changing input type hint to ghdoc as @efestwin pointed out):
import ghpythonlib.treehelpers as th
import rhinoscriptsyntax as rs
crv = th.tree_to_list(crv, lambda crv: crv)
a = []
for i,branch in enumerate(crv):
for j,item in enumerate(branch):
if rs.IsCurveClosed(item):
bool = "closed"
a.append(item)
else:
bool = "periodic"
pts = list(rs.CurveEditPoints(item))
pts.append(pts[0])
a.append(rs.AddInterpCurve(pts,1,2))