It’s always been a problem to transfer python list (specially nested lists) into grasshopper, which usually shows as: IronPython.Runtime.List
By using a piece of code in python inside grasshopper, you can easily transform python list into grasshopper DataTree and vice versa.
Here is the code:
import rhinoscriptsyntax as rsimport Rhino.Geometry as rgfrom clr import AddReference as addraddr("Grasshopper")from System import Objectfrom Grasshopper import DataTreefrom Grasshopper.Kernel.Data import GH_Pathdef raggedListToDataTree(raggedList):rl = raggedListresult = DataTree[object]()for i in range(len(rl)):temp = for j in range(len(rl[i])):temp.append(rl[i][j])#print i, " - ",temppath = GH_Path(i)result.AddRange(temp, path)return resultdef dataTreeToList(aTree):theList = for i in range(aTree.BranchCount ):thisListPart = thisBranch = aTree.Branch(i)for j in range(len(thisBranch)):thisListPart.append( thisBranch[j] )theList.append(thisListPart)return theList
To make it simpler, I’ve made two customized python user component to do the job. These components are based on scripts from Giulio Piacentino.
Below shows a basic example of using it:
The components can be downloaded here: