Treehelpers th.list_to_tree is failing to output in Grasshopper

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.

I don’t see how my script differs from this

Anyone know what’s going on? (582 Bytes)
treehelpers_test.3dm (269.7 KB) (6.0 KB)

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]
    return th.list_to_tree(layerTree, source=[0,0])
x = FindObjs()

@Tom_P Thank you!

I do know scope in Python, but I overlooked the need for a returned value here. This solves my problem