Grasshopper Lists and Trees
Grasshopper Uses Typed Lists
- A point is not a list (of numbers): it's a Point object.
- Grasshopper expects the inputs to components to be "collections",
which are trees. In the simplest case this is a single flat list. If
a component takes a Point argument, it's really looking for a
collection of points. A single Point is treated as a list of
length one.
- A terminal node in the Param Viewer tree represents a list of values,
not a single value. So a simple list of three points is drawn as a tree with
one terminal node.
- In the path notation, the numbers refer to links in the tree, not
nodes. The root is {}. A flat list by itself is normally {0}, and
is depicted as a tree with one branch. It's possible to construct a
list whose sole path is {1} or {2}, but this is not usual.
- The Line component needs two points; if its A and B inputs are both lists, it
iterates over them in parallel, using Longest by default so the last
item in the shorter list gets repeated.
- Argument enumeration is recursive, so if input A is a list of
points, and input B is a single list of a list (from Graft), then for
each A point it has to iterate over the B list (because the sole B
list item is being repeated), and we get a cross product.
- Use Display > Selected Only Preview to more conveniently examine
the contents of individual components.
The Tree Viewer
- Make a linear chain of three Param > Point components.
- Rename the first Point component "Source", the second one
"Raw", and the third one "Collect".
- Do Set Multiple Points on "Source" and click on four points in
the Rhino X-Y plane.
- Insert a Param > Util & Param Viewer component and connect
the "Collect" component to it.
- Double click on the Param Viewer to turn it into a tree viewer.
- Insert a Param > Input > Panel component and connect the
"Collect" component to it as well.
- Insert a new Param > Point component below "Raw", and name it "Copy".
Connect the "Source" component to its input. Make the output of
"Copy" be an additional input to the "Collector" component.
- Now the Panel shows 8 elements instead of 4.
- Disable the Raw component. Now there are only 4 elements again.
- Turn on Graft for "Copy" and rename it to "Grafted". Now you
see a tree.
- Enable the Raw component. Notice that the tree doesn't change:
if a node has both data and branches, only the branches are
displayed. But the panel shows everything.
- Insert a Sets > Tree > Path Mapper component below the previous
middle Point components, and set it to map {A}(i) to {A+2;i+5}.
- Feed the Source component into the Path Mapper, and
make the Path Mapper's output be an additional input to the
"Collect" component.
- Play with enabling and disabling components to see how the tree
and panel changes.
Argument Enumeration
- Make two Param > Point components.
- Right click on each one and choose "Set one Point". Put the
second point to the right of the first one and slightly above.
- Insert a Curve > Primitive > Line object and connect the points.
- Right click on the Point components and choose Set Multiple
Points. Set the first component to 3 points and second to 4 points.
- Notice that if GH runs out of values, by default it repeats the last one.
- Try the Set > List > Shortest component.
- Try the Set > List > Cross Reference component to get an outer product ("holistic").
- Insert Param > Util > Parameter Viewer, double click on it to switch to Draw Tree mode.
- Use Set > Tree > Graft to graft one tree to generate a cross product.
- Use Set > Tree > Flatten to flatten the cross product.
- Can also set the Flatten attribute of the output node.
More On Cross Products
- Make two Param > Primitive > Number components.
- Set the first component to 3 numbers and the second to 5 numbers.
- Insert a Vector > Point > Construct Point component and connect the number parameters to it.
- Draw the output tree using a Param > Util > Param Viewer.
- Turn on grafting for one of the number parameters and observe the result.
- Turn on grafting for just the other number parameter; how does the tree change.
- Turn on grafting for both number parameters. Now what?
- Go back to only one grafted input.
- Insert a Display > Vector > Points List component. Set the S parameter to 1.
- Turn on flattening for the P input to the Points List component and observe how the numbering changes.
- Make a truss by inserting a Surface > Freeform > Pipe component and feeding the lines
into its C input. Set the E input to 2 to cap the pipes.
Lists
- Use Set > List > List Item to extract specific items from a list.
- Uset Set > List > Dispatch to take subsets of a list, e.g., elements ≥ 5.
A Video Tutorial on Grasshopper Data Trees
If you want to see more material on this subject see this YouTube
video, Grasshopper Lecture
4: Data Trees, Structure.
|