Grasshopper

algorithmic modeling for Rhino

Hello,

I'm trying to understand how to work with data trees in GHPython, and am having problems with the very basics.

For instance, here is something that for the love of me I can't figure out (the complete code is written in the scribbles):

The only thing I changed between the first and second image is connecting the square grid. I never touched the access or type hints of the Python components.

1. Why would the square grid affect the other components' outputs like that? In the first component I never even mentioned "x".

2. Why does "a=x" turn the nested list of the first component into a data tree? Judging from other posts the process to do this in one Python component seems quite complicated.

Any explanations, tips and comments would be much appreciated!

Cheers,

Max

Views: 1276

Replies to This Discussion

Hi Max

the GH-specific concept of trees is a bit complicated to program, but has been covered in a lot of questions, also regarding Python access.

The basic thing to note in your sample is that a tree accepts a single enumerable ("list") as a branch. So you cannot just pass a list of lists to the tree, as the exact place where the lists of lists should go is not trivial. If there is only one enumerable (a single "list"), then the content can be placed in the right branch. The reason that passing through several Python components reduces nested lists is just that every enumerable become an inner branch.

This GitHub Gist page contains a sample about converting a nested list into a tree, and a tree to a list (there are some conditions for this to be actually possible, but in normal usage it is). Iteration over a tree is covered here.

Does it help?

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

Thanks Guilio,

That does clarify things a bit more, but I'm not sure it answers my first question. I did actually find a lot of information on how to build and read data trees in Python, but the thing I still can't wrap my head around is how - in my example - inputting the square grid can have an effect on the further flow of data.

In the first GHPython component I simply defined a nested list of numbers as an output. I didn't do anything with the square grid, so why does it affect the output at all? The square grid seems to cause GHPython to create duplicates of the output, but shouldn't it be irrelevant?

Sorry, I must be missing something basic here...

Cheers,

Max

I understand now what you were meaning with the question 1. .

This is a requirement of [item, list, tree] iteration logic.

You will understand it with this example:


You have a script that accepts an item, in this case, a number, and increments it by one.

a = x + 1

  • You feed it with a single item, 6. All will be well. Your output will be a 7.
  • You input a list with 4 items, [2,3,4,5] and do not change the input 'Item Access' to other values. Output will be [3,4,5,6]. The script will run 4 times.
  • You feed it with a tree: {0}[1], {1}[2]. Output will be something akin to {0}[2] {1}[3]. Your script will run twice, once for each item in each branch of the tree.

This means that inputs determine the amount of iterations of scripts.
If you put a tree like above into a component, the component will have to run many times to cope with the inputs.

Does it help?

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

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service