3.3. Lists
Data Lists in Grasshopper
A List is an ordered (but not necessarily sorted) collection of data. Lists may contain zero elements, a single element, or (at most) 2,147,483,647 elements. The same element can occur more than once in the same list, and different elements with identical values. Also, a list may contain empty elements, referred to as nulls.
When storing data in a list, it’s important to know the position of the items in that list in order to access or manipulate them.
The position of an item in a list is called Index Number.
Points
, Curves
, Surfaces
, Meshes
, etc…
Range
List of equally spaced numbers between a Low and a High value is called Domain. A domain is every possible number between two numeric extremes.
A Range (Set > Sequence > Range) component divides a numeric domain into even segments and returns a list of values.
List Visualization
We can visualize Data contained in lists in different ways in order to understand and manipulate them:
Point List
Displays the Index Item Number next to the point geometry in the viewport.
Text Tag
Draws strings as feedback items. When text tags are baked into the scene, they turn into Text Dots.
Color
We can visualize the data of a list by assigning color to it. You can find it on Params > Input > Gradient.
The L0 value represents the low end (left side) of the gradient, whereas the L1 value represents the upper end (right side). These values correspond to the Start and End of our domain. The t-values are the elements in the list that will get mapped somewhere within the L0 and L1 range.
The output of the gradient is a list of RGB color values which correspond to each point in our list.
List Manipulation
The strength of Grasshopper is to quickly build and manipulate lists of data:
List Length
Measures the length of the List.
List Item
To find a specific data item from within a list.
When accessing individual items in a list, we have to specify the index number we would like to access, that can be a single integer or a list of integers.
Reverse List
To invert the order of the list.
Shift List
We can move the list index up or down depending on the value of the shift offset.
If we set the “Wrap” value to False, we will remove the last value. However, if we set the “Wrap” value to True, the first entry will be moved to the bottom of the list.
Insert Item
Insert a collection of items into a list.
You need to know the items you want to insert and the index position.
Cull Pattern
Removes elements in a list using a repetitive pattern.
The pattern is defined as a list of Boolean values (True or False).