I have implemented Treehelpers in a python script (attached). I am running the script in a GhPython component. When I connect a panel to an output named x, I have a null value, thogh when I print the list of lists, I get values (see screenshot). This means to me that the failure is in my use of Treehelpers.
the variable x inside the Function “Main” has not the expected scope.
check some info on “scope”.
is this what you re after ?
import Rhino.Geometry as rg
import rhinoscriptsyntax as rs
import random
import Rhino
import ghpythonlib.treehelpers as th
import System
import scriptcontext as sc
def FindObjs():
layerTree = []
layernames = ["CurveLayer1", "CurveLayer2","CurveLayer3"]
for i in range(len(layernames)):
objs = Rhino.RhinoDoc.ActiveDoc.Objects.FindByLayer(layernames[i])
if objs:
geoms = [obj.Geometry for obj in objs]
layerTree.append(geoms)
print(layerTree)
return th.list_to_tree(layerTree, source=[0,0])
x = FindObjs()