Grasshopper

algorithmic modeling for Rhino

Is it possible to get a "tree structure in python explanation for dummies/noobs" ..

I like to get an arbitrary tree structure converted to some kind of list in list structure. e.g. [[pt1,pt2,pt3][pt4,pt5][[pt6,pt7][pt8,pt9]]

After manipulating the list in list structure in python it should be converted back to a similar tree structure. (inside a single python component)

Views: 2379

Replies to This Discussion

Hi Thomas

trees are complicated to use successfully in Grasshopper, and even more so to use programmatically. Luckily, often they can be ignored by working on items or studying a better type of definition. Occasionally, though, you really have to work with them.

I still would like to point out that it might not be your case. Maybe there is another way to approach this entirely within your definition. Saying this, I assume you are trying to achieve something in particular with this lists of lists exercise, and not trying to just do this as a standalone drill.

Finally, please have a look at this discussion. Benjamin posted a NestedListToDataTree function that might help you. However, obviously copying a data structure after-the-fact will be slower than creating it from scratch. You can always use that and the rest of the code on that page as a sample of how to construct a tree.

I hope this helps,

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

Hi Giulio

Thanks for the answer! I thought I had said it :-S .. hmm

Benjamins scripts works perfectly! 

I not sure how the list in list would be created? 

two for loops? one counting the number of branches (list in list) and the second one filling in the items.. How do i count the items in each branch? :-S 

e.g. something like: 

list = []
for i in range(>>>>pt. ItemCount )
    for j in range(pt.BranchCount):
        list.append([>>>> pt item in each branch [i] ])

Hi Thomas,

You can use the dataTree.Branch method to retrieve the list from it.
Check the attached file.

Again, as Giulio mentioned, all of this could be done without messing with data trees, setting the input to "Item access" and letting grasshopper do the rest on its own.

Attachments:

Ty djordje

That's just what I needed :-)

hi giulio

trees are complicated, yes!

even the basic shift path of grasshopper is difficult for me.

i want to use it inside python and i think to use GH_PathOffset.OffsetPat but i don't know hoe to set it correctly.

i have:

objects (input object as datatree into python component) structure={A;B;...;V;Z}

i want to shift that path like that: {a;B}-->{A} but i don't want to use LexicalReplace but something like offsetpath.

can you explain me how do use it???thank you very much.

the approach to gh sdk and scripting in general is really difficult.

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service