Grasshopper Basic List Actions
Introduction
Grasshopper uses, in contrast to a programming environment, no object names to define an object. This may sound trivial but it is one of the most fundamental differences from a traditional modelling environment. In Grasshopper the object or objects are placed in a list. The different lists of data are organized in a data tree structure where every branch and data content of the branch have an index number. Accessing the object is therefore more problematic then in a scripting environment. Grasshopper has various tools to remedy this problem. These tools supports the editing and selecting the content of the lists. Knowledge of these techniques are essential for the effective use of Grasshopper. These skills will be explained in this wiki. To keep the examples simple, a panel with numbers is used. These numbers can represent many different things. For example: points, curves or surfaces.
List item
The List item selects an item or multiple items from the list. Take note of the indices in the input list (numbers in front of the value). The indices start at 0, not at 1.
You can also take multiple items from a list.
List length
The list Length component returns the number of items in a list.
In the second example List Length is used to obtain the last item in the list, regardless of the number of values. This makes this definition parametric. Note that you will need to subtract 1 from the list length since the indices start at 0!
Reverse list
The purpose of reverse list is quiet obvious. This component can also be used to get the last item of the list by reversing the list and get the 1st item (index 0).
Shift list
Shift list moves the items in the list by the shift value (S). A positive (S) moves the items up in the list and a negative (S) down. Wrap around (W) prevents items from "falling off" the list by moving them to the other end.
Sorting list
The sort list component can be a very powerful one. Its default functionality is to sort the list (K).
Aside from that input there is the possibility to attach more lists (A,B enz.) These lists will be sorted in the same order as the first list. The content of the secondary lists doesn't need to be sortable as the first list (K) should be. The second list can be geometry, text etc.
Split list
Split list splits a list into two seperate list. The second list starts with the index (i).
Sub list
With sub list you can select a part of a list using a domain. Elements outside the specified domain will be eliminited from the output.
Partition list
Partition list works as a combination of the "split list" and the "sub list" components. Input (S) sets the split pattern by the amount of items each list should contain. This pattern will be repeated until all items are placed.
Replace Items
Replace item replaces a specific index with a value or string. The item input defined what the index should be replaced with.
Cull Actions
Now that we have discussed the methods to change lists by moving items, it is important to look at the cull options. Cull nodes are used to remove one or multiple items from a list.
Cull Index
Remove the item of one or multiple indices of a list.
Cull Nth
Remove every Nth item of a list. The Cull frequency holds the N input.
Cull Pattern
Cull items based on a True-False boolean pattern.
Advanced list editing tools
Dispatch
By adding a pattern of True and False booleans to the dispatch pattern, you can create two different lists, based on the dispatch pattern.
Sift pattern
Sift pattern can create multiple lists based on a pattern.
Weave
Weave does the opposite of dispatch. It combines two lists into one, based on a pattern.
Random Reduces
Shuffle the list and remove N items. The reduction input holds the value for N.
Data Matching
Data matching is explained in Tutorial 5 - Creating Grids. By using the data matching nodes, you can alter the length of a list, based on another one. This gives you the possibility to combine the data more easily in a later stage.
Shortest List
Shorten the longest list based on the length of another list. This can be done by, for example, trimming the end. Other options are also available.
Longest List
This node does the opposite of shortest list. It makes the shortest list longer based on the length of the shortest list. This can be done by, for example, repeating the last item.
Cross Reference
Cross reference combines two list by multiplying both lengths. The used variables depend on the output you choose.