How can I output geometry from a GH Python component?

Learn Python Scripting v0109.gh (12.1 KB)

I am learning GH Python.
I like to output geometry (curves, surface from loft) from the script component, but I keep getting “1. Data conversion failed from Goo to Curve” error.

How can I get the geometry?

ptMatrix = {}
for z in range(zMax):
    for y in range(yMax):
        for x in range(xMax):
            ptMatrix[(x,y,z)] = (x*gap,y*gap,z*gap)


curvesdict = {}
for i in range(yMax):
    curvesdict[i] = []

for y in range(yMax):
    for x in range(xMax-1):
        for z in range(zMax-1):
            pt1 = ptMatrix[(x,y,z)]
            pt2 = ptMatrix[(x+1,y,z)]
            pt3 = ptMatrix[(x+1,y,z+1)]
            pt4 = ptMatrix[(x,y,z+1)]
            pts = [pt1,pt2,pt3,pt4,pt1]
            crv = rs.AddCurve(pts)
            curvesdict[y].append(crv)

# results = list[curvesdict.values()]

loft = [ ]
for i in range(len(curvesdict[0])):
    curves = [curvesdict[y][i] for y in range(yMax)]
    loft.append(rs.AddLoftSrf(curves))

results = loft

if you want to output data trees, treehelpers from ghpythonlib is your best friend

list_to_tree exports List data structures as data trees, and tree_to_list import trees as lists (of list (of lists (of lists…)))

Learn Python Scripting v0109_treehelpers.gh (18.0 KB)

1 Like

Oh, I got it, so there is no direct output from python list, I have to convert the list to data tree. Thank you! @inno

1 Like