Hello everyone,
I would like to learn how to do tree operations using Python.
Could anyone address me to some tutorials?
Thanks
Hello everyone,
I would like to learn how to do tree operations using Python.
Could anyone address me to some tutorials?
Thanks
I donāt know of any specific tutorials, but in R6, (I think thatās when it was introduced), you can use treehelper functions., (after importing ghpythonlib)ā¦also assuming you are referring to the ghpython component.
here is a link to one example that I know of, (Iām sure a search of the forum would turn up more/better references).
Thereās also this page, but we are working on it:
Thanks,
Giulio
ā
Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com
Thereās also the documentation of the DataTree
class itself:
https://developer.rhino3d.com/wip/api/grasshopper/html/T_Grasshopper_DataTree_1.htm
And some minimal examples for reading and writing two dimensional trees:
Read:
""" Read the Grasshopper Datatree "FooTree" and translates it to
a nested Python list """
pyList = [list(b) for b in FooTree.Branches]
Write:
import Grasshopper as gh
def listToTree(nestedList):
""" Convert a nested python iterable to a datatree """
dt = gh.DataTree[object]()
for i,l in enumerate(nestedList):
dt.AddRange(l,gh.Kernel.Data.GH_Path(i))
return dt
And Giulios more advanced helper functions that reads/writes arbitrary nestings:
So I donāt know if I am going crazy or not. First of I have successfully manipulated trees and list before pre and post tree helpers. I tried using tree_to_list but got:
Runtime error (MissingMemberException): āstrā object has no attribute āBranchCountā
thought that was odd so I tried the pre treehelper (R5) workflow as described in:
Still having problems so then I downloaded the sample file there. Now this is where it gets weird. The python components from the example file i downloaded worked, however I copy and pasted the same code to a fresh Py component and it was giving me the same sort of errors:
āstrā object has no attribute āBranchCountā (or āBranchā)
My original code that I wrote was copy and pasted into this ādownloadedā component worked. I checked the Lib imports from the SDK mode as well and both are the same. Anyone else having this sort of problem? I feel like Iām taking crazy pills!
fresh pythong component of the left, downloaded component on the right:
Have you changed the input to tree access?
O__O Thanks for proving Iām crazyā¦ haha
Hi, how do I call the tree class in python?
Thereās a method I wish to use. Itās the renumber branches to ascending numbers.
But, I cannot use without calling tree class firstā¦?