Skip to content

Instantly share code, notes, and snippets.

@StepMaher StepMaher/list_to_tree.py
Last active Nov 4, 2015

Embed
What would you like to do?
"""
Creates a data tree from a list.
Inputs: list: List to make a tree.
Outputs: tree: Output tree.
"""
# Name component
ghenv.Component.Name = "List to Data Tree"
ghenv.Component.NickName = 'ListTree'
# Import libraries and methods
from Grasshopper.Kernel.Data import GH_Path
from Grasshopper import DataTree
newTree = DataTree[object]() # Declare new DataTree
for i in range(len(list)): # Iterate items in list
item = x=list[i]
path = GH_Path(0,i) # Explicity construct path for each branch
newTree.AddRange([item], path) # Adds a list to the DataTree with specified path
tree = newTree # Associate with output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.