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])

    # b = th.list_to_tree(a)

Uncommenting the last line of code crashes Grasshopper (12.6 KB)

Here’s another file where I struggle with the list to tree definition: (12.2 KB)

I tried to use ghpythonlib.treehelpers and now this file crashes Rhino right away when opening… (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 in the %HOMEPATH%\.rhinocode\python3.9-??\site-rhinoghpython\ghpythonlib\ with this file (replace python3.9-?? with whichever python 3.9 path you have) (2.8 KB)

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

1 Like

Fixed already?

Thank you!!!

1 Like