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
Tags:
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
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
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by