Grasshopper

algorithmic modeling for Rhino

Hi Guys.

One thing that has been a little tricky to me for a while: When adding a GH dataTree to a Python component e.g:

{0;0}

{0;1}

{0;2}

{1;0}

{1;1}

{1;2}

In Python branch {1;0} is tree.Branch(3) right? When the dataTree is this simple its not really a problem, but when it grows and I want to be able to refer to a specific GH branch e.g. {11;320} and I need to read this specific branch in Python? How do I do this?

I know that there is the function tree.Path(x) this will give me the GH Path, but how do I figure out what x needs to be? I guess there must be a simple answer :).

Thanks Rasmus

Views: 4552

Replies to This Discussion

I guess this was a typical case of "speaking" before really "thinking"/looking. 

tree.EnsurePath(x,x) seems to do the trick. 

Maybe someone else can use this info, otherwise we might just delete this post :)

I think you can also make the path directly

sel_path = GH_Path(11,230)

tree.Branch(sel_path)

but if i am not wrong you have to import the Grasshopper.Kernel.Data namespace for the Python component first.

Okay thanks. :)

Hi Rasmus

 

all answers are correct here. One more thing is: you could also iterate over paths, not branches:

 

a = []

for path in x.Paths:

    one_list = x.Branch(path)
    print(path)

    first_item = one_list[0]

    a.append(first_item)

Maybe this could also be helpful,
Giulio
--
Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com

Attachments:

Hi Giulio.

Oh yeah of course. That is a nice method as well.

Thanks.

Rasmus

This closed out a while ago, however this seemed like a good place to ask:

How can you easily reference all "beta branches" of a "Alpha Path" if we think of complex branching in terms of {Alpha path, Beta_branch} 

Below is my solution but it seems like making a Paths data tree shouldn't be necessary, and would fall apart if the tree grew to include gama or delta sizes: ie  GH_Path = {alpha; beta; gama ; delta}

I suspect the answer is simple:

Attachments:

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service