algorithmic modeling for Rhino

Hi all,

I have a python script which is iterating through a data tree. The incoming branches look something like this:








I'm iterating through using:

for i in range(inputTree.BranchCount):
    inputThisBranch = inputTree.Branch(i)

...which graps each branch in sequence. I was wondering if it was possible to then:

a) get the first index numbers of each branch an integer, ie. '0' for the first branch, '1' for the next three, '2' for the next two...

b) get the 'depth' of the path for all branches, ie. '2' for each

Is there a way to do this? I haven't been able to find the answer by searching...



Views: 1995

Replies to This Discussion

Yes, to get this information you have to also iterate over the Paths of the tree

for i in range(inputTree.BranchCount):

  inputThisBranch = inputTree.Branch(i)

  pathLength = inputTree.Path(i).Length

  pathFirstNumber = inputTree.Path(i)(0)


David Rutten

Brilliant! Thanks

Just a small addition to David's reply:
Use square brackets when accessing element from python sequences:

pathFirstNumber = inputTree.Path(i)[0]

If you use list_to_tree, you can transform this forest into a list of list as well. See this example:






  • Add Photos
  • View All


  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service