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.

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 *gt; 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 &gr; 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