Documentation Grasshopper API

Python_III_Grasshopper - Create a data-tree from a nested list:


import Grasshopper 

my_list = [[0,1,2],[5,6,7],[10,11,12]]

datatree = Grasshopper.DataTree[int]()
for i in range(len(my_list)):
    datatree.AddRange(my_list[i], Grasshopper.Kernel.Data.GH_Path(i))

a = datatree

Python_III_Grasshopper - Convert a data-tree to Python nested list:


import Grasshopper 

my_list = []

for i in range(x.BranchCount):
    my_list.append(list(x.Branch(i)))

a = my_list


You can also use “ghpythonlib.treehelpers” helper functions for converting data tree to lists and vice versa in one single line (with some exceptions).