Grasshopper

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:

{0;0}

{1;0}

{1;1}

{1;2}

{2;0}

{2:1}

{3;0}

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...

Thanks,

Ben

Views: 2089

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

david@mcneel.com

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:

https://gist.github.com/piac/ef91ac83cb5ee92a1294#gistcomment-3763417

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service