3.6. Data Operations
Data operations in Grasshopper
Data Operations
Data operations can happen at different levels:
- Single level
- Lists level
- Tree level
Single level operations
Many components operates on individual values and also output individual values as result:
Lists level operations
Other category of components create lists of data from single input values:
Occurring also the opposite behavior:Many components only operates on lists of data and also output list of data:
Tree level operations
Some few components output several list points, each of them representing a row or column in a grid:
We can also access to specific items in the Data Tree:
Or we can just operate them keeping or modifying its Data Tree structure:
List Manipulation
Most of the operation in Grasshopper will happen at List level and Grasshopper is specially good at quickly building and manipulating lists of data.
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.
The Range component divides a numeric domain into even segments and returns a list of values.
- Sets > Sequence > Range
List Length
Measures the length of the List.
- Sets > List > List Length
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.
- Sets > List > List Item
Reverse List
To invert the order of the list.
- Sets > List > Reverse 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.
- Sets > List > Shift 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.
- Sets > List > Insert Item
Cull Pattern
Removes elements in a list using a repetitive pattern.
The pattern is defined as a list of Boolean values (True or False).
- Sets > Sequence > Cull Pattern
Flatten tree
Flatten removes all levels of a Data Tree, resulting in a single List.
- Sets > Tree > Flatten Tree
Graft Tree
Graft Tree creates a new Branch for every Data Item.
- Sets > Tree > Graft Tree
Simplify tree
Simplify a data tree by removing the overlap shared amongst all branches.
- Sets > Tree > Simplify Tree
Flip Matrix
Flip Matrix component Swaps the “Rows” and “Columns” of a Data Tree with two Path Indices.
- Sets > Tree > Flip Matrix
Comparison operators
Comparison operators are used to compare values.
They return Boolean values based on whether a comparison is True or False.
- Maths > Operators
Booleans
Boleans variables can only store two values:
- TRUE (1)
- FALSE (0)
Boolean Toggle allows you to quickly change between single True or False values:
Grasshopper has components to test conditions and output Boolean values:
Check if a number is contained inside a certain Domain:
- Maths > Domains > Includes
Logical operators
Logical operators mostly work with Booleans.
Gate NOT performs boolean negations.
- Maths > Operators > Gate NOT
AND and OR components takes two arguments as input. Logical operators are used to evaluate something.
- Maths > Operators > Gate AND
Different combinations:
A | B | Result |
---|---|---|
True | True | True |
True | False | False |
False | True | False |
False | False | False |
- Maths > Operators > Gate OR
A | B | Result |
---|---|---|
True | True | True |
True | False | True |
False | True | True |
False | False | False |