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