algorithmic modeling for Rhino
I am having trouble converting multi dimensional python lists to a data tree
the following works
def PyListToDataTree(PyList):
result = DataTree[object]()
for i in range(len(PyList)):
temp = []
for j in range(len(PyList[i])):
temp.append(PyList[i][j])
path = GH_Path(i)
result.AddRange(temp, path)
return result
but how would one modify this so it can handle 3D and 4D lists
Tags:
You're going to have to make more complicated paths. Instead of GH_Path(i), you'll have to append each list using a path like GH_Path(i,j,k)
--
David Rutten
david@mcneel.com
Thx for the quick reply David
I understand I will need to specify path = GH_path(i,j,k) for a 3D array. However i am not clear on how i should iterate through the python lists and add the path's. Ive tried the following but the output is incorrect
def PyListToDataTree(PyList):
result = DataTree[object]()
for i in range(len(PyList)):
for j in range(len(PyList[i])):
temp = []
for k in range(len(PyList[i][j])):
temp.append(PyList[i][j][k])
path = GH_Path(i,j,k)
result.AddRange(temp, path)
return result
Looks correct to me -at least in principle-. Python isn't my strong suit though so I shan't comment too much.
How is the output incorrect?
--
David Rutten
david@mcneel.com
Try this one:
def PyListToDataTree(PyList):
result = DataTree[object]()
for i, listsOfLists in enumerate(PyList):
for j , otherList in enumerate(listsOfLists):
for k, finalList in enumerate(otherList):
path = GH_Path(i,j,k)
result.AddRange(finalList, path)
return result
Cheers, works like a charm
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by