List To Tree problem with new script editor - worked fine in Rhino 7

if on:
    import Rhino
    import os
    import ghpythonlib.treehelpers as th

    a = []
    b = []
    path = None

    if (dir is not None):
        dir = dir.strip()
        if dir.endswith(os.sep):
            dir = dir[:-1]
        if (os.path.isdir(dir)):
            path = dir

    if (path is None):
        path = os.path.dirname(ghenv.Component.OnPingDocument().FilePath)

    print("Search Path: {}".format(path))

    dirList = os.listdir(path)

    for file in dirList:
        results = []
        if (file.endswith(".3dm")):
            file_w_path = os.path.join(path, file)
            rhinoFile = Rhino.FileIO.File3dm.Read(file_w_path)
            notes = rhinoFile.Notes.Notes
            results.append(["Path: {}".format(path), "File: {}".format(file), notes])
            print(results)
            a.append(results)

    # b = th.list_to_tree(a)

Uncommenting the last line of code crashes Grasshopper

notes_in_directory_python.gh (12.6 KB)

Here’s another file where I struggle with the list to tree definition:

permutations_combinatorial_python.gh (12.2 KB)

I tried to use ghpythonlib.treehelpers and now this file crashes Rhino right away when opening…

python_treehelpers_problem.gh (13.4 KB)

@martinsiegrist I can replicate the crash. I’m on it. Thanks for the report

RH-76856 Treehelps crash when creating a tree from a list of strings

1 Like

@martinsiegrist I found where the bug is and got it fixed. Has something to do with string types in python 3 implement __iter__ methods but not in Python2/IronPython2 so that would cause an infinite recursion and crash.

I’ll have this fixed for next release but in the meantime you can replace the treehelpers.py in the %HOMEPATH%\.rhinocode\python3.9-??\site-rhinoghpython\ghpythonlib\treehelpers.py with this file (replace python3.9-?? with whichever python 3.9 path you have)

treehelpers.py (2.8 KB)

I added this test to my tests
test_treehelpers.ghx (38.3 KB)

1 Like

Fixed already?

Thank you!!!

1 Like