Treehelpers with weird runtime error

When doing the quite normal

output = ghpythonlib.treehelpers.list_to_tree( nestedList )

I get the weird runtime error:

Runtime error (MissingMemberException): ‘type’ object has no attribute ‘__index__’
Traceback:
line 32, in list_to_tree, […]

I’m not really sure why this comes up. Maybe @DavidRutten knows something?
Or somebody else ever had this error?

Using output = nestedList does “work” (you’ll get “IronPython.Runtime.List” of course).
output = nestedList[0] also works fine, you get what you’d expect.

without seeing the context…(no file), I’l guess and suggest this…:

output = ghpythonlib.treehelpers.list_to_tree(nestedList, True)

Thanks for your answer, Chris!
Sadly it doesn’t seem to help, tho.

There are too many LoC, but stripped down it’s basically like this:

class MyAgent():
    # init ....
    # 
    def make_some_geom(self):
          # make some geometry here
          nestedList[self.ID].append(someGeom)


if "agentsList" not in globals():
    agentsList = []
    nestedList = [[] for i in range(nAgents)] # make empty (sub-)lists so I can append later

#... init the agents here with ID

if RUN: # run is a bool toggle
    for agent in agentsList:
            # of course there is actually more here and not this function call directly
            agent.make_some_geom() 
            ghenv.Component.ExpireSolution(True)  # instead of the timer component

# output
output = nestedList #....

@piac might be able to offer some further insight. I would guess it’s your nested list structure…
maybe this sample helps? (dummy example to show a basic nested list structure).

import ghpythonlib.treehelpers as th

uPts = []

# reparameterize input surface
S.SetDomain(0, Rhino.Geometry.Interval(0,1))
S.SetDomain(1, Rhino.Geometry.Interval(0,1))

# create columns of points on surface
# using a nested list will allow conversion to datatree
for i in range(0, U):
    newColumn = []
    for j in range(0, V):
        newColumn.append(S.PointAt(i * (1 / (U - 1)), j * (1 / (V - 1))))
    uPts.append(newColumn)
    
a = th.list_to_tree(uPts, True)

List2TreeSample.gh (6.5 KB)

how are you appending the empty lists?
this little snippet seems to work okay…

import ghpythonlib.treehelpers as th

nAgents = 5
agentsList = []
nestedList = [[i] for i in range(nAgents)] 

a = th.list_to_tree(nestedList)

I’m not sure why, but when I started Rhino today, my inital code (with treehelper) suddenly worked – no runtime errors so far.
¯\_(ツ)_/¯

https://www.timeanddate.com/moon/phases/

4 Likes

Excellent! I’ll flag this as the correct answer, I guess… :joy:

1 Like