I am trying to mess around with DataTrees in Python.
I need to cull one item from a branch, if the length of lists in a branch is odd.
However, when I do so, it stacks all the items in one branch, culls all the branches that are odd, and returns 1 stacked branch and even branches…
What am I doing worng?
appendTree.gh (26.4 KB)
Is there a reason for using tree access? Because with list access you could just do:
Thanks for reply Adam!
I want to learn how I can access and change data within a branch in python, without affecting the tree structure.
But also, I need to work with DataTree, cause I am working with multimodular geometry like so:
If I understand your intent, you are trying to cull the last item from the branches with odd indices.
appendTree_re.gh (8.3 KB)
Edit: There are more efficient ways of doing this, I was trying to minimally modify your code. Instead of iterating the list, you could delete the last item with:
appendTree_re2.gh (8.4 KB)
Edit2: Further simplified, you can just modify the original tree and pass it on to the output (only had a couple of minutes to look at this earlier):
import rhinoscriptsyntax as rs
import scriptcontext as sc
import Grasshopper as gh
import ghpythonlib.treehelpers as th
from pprint import pprint
for i, branch in enumerate(x.Branches):
if branch.Count % 2:
DT = x
appendTree_re3.gh (8.6 KB)