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

  1. Make a linear chain of three Param > Point components.
  2. Rename the first Point component "Source", the second one "Raw", and the third one "Collect".
  3. Do Set Multiple Points on "Source" and click on four points in the Rhino X-Y plane.
  4. Insert a Param > Util & Param Viewer component and connect the "Collect" component to it.
  5. Double click on the Param Viewer to turn it into a tree viewer.
  6. Insert a Param > Input > Panel component and connect the "Collect" component to it as well.
  7. 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.
  8. Now the Panel shows 8 elements instead of 4.
  9. Disable the Raw component. Now there are only 4 elements again.
  10. Turn on Graft for "Copy" and rename it to "Grafted". Now you see a tree.
  11. 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.
  12. 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}.
  13. Feed the Source component into the Path Mapper, and make the Path Mapper's output be an additional input to the "Collect" component.
  14. Play with enabling and disabling components to see how the tree and panel changes.

Argument Enumeration

  1. Make two Param > Point components.
  2. Right click on each one and choose "Set one Point". Put the second point to the right of the first one and slightly above.
  3. Insert a Curve > Primitive > Line object and connect the points.
  4. Right click on the Point components and choose Set Multiple Points. Set the first component to 3 points and second to 4 points.
  5. Notice that if GH runs out of values, by default it repeats the last one.
  6. Try the Set > List > Shortest component.
  7. Try the Set > List > Cross Reference component to get an outer product ("holistic").
  8. Insert Param > Util > Parameter Viewer, double click on it to switch to Draw Tree mode.
  9. Use Set > Tree > Graft to graft one tree to generate a cross product.
  10. Use Set > Tree > Flatten to flatten the cross product.
  11. Can also set the Flatten attribute of the output node.

More On Cross Products

  1. Make two Param > Primitive > Number components.
  2. Set the first component to 3 numbers and the second to 5 numbers.
  3. Insert a Vector > Point > Construct Point component and connect the number parameters to it.
  4. Draw the output tree using a Param > Util > Param Viewer.
  5. Turn on grafting for one of the number parameters and observe the result.
  6. Turn on grafting for just the other number parameter; how does the tree change.
  7. Turn on grafting for both number parameters. Now what?
  8. Go back to only one grafted input.
  9. Insert a Display > Vector > Points List component. Set the S parameter to 1.
  10. Turn on flattening for the P input to the Points List component and observe how the numbering changes.
  11. 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

  1. Use Set > List > List Item to extract specific items from a list.
  2. 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.

Dave Touretzky