Issue with simplified trees in python

grasshopper
python
bug
tree
simplify

#1

I’ve noticed an issue with how python interprets trees using the treehelpers.tree_to_list method.

When a simplified data structure is plugged in, the tree_to_list function only returns the first tree of data and discards all the other branches.

python_tree_simplify.gh (12.6 KB)


(Giulio Piacentino) #3

That is by design.

A simplified tree actually is a ‘forest’: each tree has no common path with other trees. This case was handled originally, so that lists would not have to always be nested within a list of a single item. (when all branches start with 0, which they usually do). There is also the discrepancy of multiple items that should be grouped and yet have no common path, which happens with ‘forests’. This fixes both things.

You can see that the th.tree_to_list() function has a second input. It’s the retrieval function. If all your paths start with ‘0’, then the default lambda x: x[0] will work best. If they all start with different numbers, then use lambda x: x. Etc…

a = th.tree_to_list(x, lambda x: x)

Thanks,

Giulio


Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com

python_tree_simplify_design.gh (14.3 KB)