Grasshopper

algorithmic modeling for Rhino

I'm sure this has been asked over and over so I apologize but when I search the discussion for "Trees" I get 80 pages so I guess I'll just ask again...

Why does a series or 10 items produce a tree with one element which is a list of 10 numbers?

I can flatten it and get (I think) a list of 10 elements (even though when I hover over the output of "Flatten" it says "Tree(T) as tree").  I'm surprised I can flatten at all what would appear to common sense to be a simple list of 10 numbers.

I'm hoping that if I can get this answered it will become obvious why we have trees of lists rather than just lists of lists as you would in most computer languages.  That's my real goal - to understand the purpose of adding what seems like an unnecessary complication - trees - to the concept of lists in GH.  It seems to me as though a "tree" is just a list of other "trees" until you get to the leaves where you can have "lists" which are identical to trees but can have something other than a tree in them.  Whether you can have lists of trees or trees with no lists I'm unclear on.  Do the leaves of trees have to be lists?  Do lists have to be contained in trees?  It would appear from the series example where a tree is produced for no obvious reason to contain the list that this is the case but given that you can flatten it, I guess not - or is the "List" I see in the param viewer just another type of "tree"?

I've found many tutorials that talk about how to manipulate trees and lists and I've managed to get along fairly well with them so far, but nothing seems to explain the reasoning behind the existence of trees and the philosophy for how and when they should be used and when lists should/could be used and precisely what the difference is between them.

Sorry to be long winded but I'm so confused!

Darrell Plank

P.S.  I've seen David Rutten's diagram with the colored leaves in Grasshopper Primer 2 and that seems helpful.  It would appear that trees can only have lists at their leaves and lists can't have trees although I'm not sure that it comes out and says that directly but at least there are no examples of this shown in his tree diagram.  I thought I had it down pretty much so decided to test myself.  Apparently I'm as confused as ever:

It certainly appears to me that this tree has two levels - a first level with one limb and a second with 10 limbs - and that I should be able to index it with {0;0} and retrieve a tree with one item in it - the list {0}.  The panel data seems to confirm this with indices of {0;0;0}, etc. so I put this path in with quite a bit of confidence that it would work and...bust.  The error reads "Path {0;0} does not exist within this tree".  Huh?  Again, I'm just so confused.

Views: 2074

Replies to This Discussion

Ah - things are finally starting to click into place and I can feel my poor mind start to feel more comfortable in the GH world.  Many questions answered.  Thanks so much!

Param Viewer doesn't give a "real" GH error - it just puts up a big circled exclamation mark in the "Draw Tree" mode which I'm sure is exactly what is intended.  I was just calling it an "error" as shorthand but sorry for the confusion.  Addendum:  Oops!  Now that I go back and look at it, it only gives the exclamation mark when I haven't actually assigned a value to the "Number" parameter so it's input is empty.  That's more than reasonable.  When I put in a number I get a tree drawn exactly as I would expect given your explanation.

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service