The methods presented below can be used to extract or remove items or subsets from lists. The components operate on given indices or patterns of Boolean values. The how-to Search lists deals with a similar operation: searching lists for specific items.
Retrieve items per index (List Item)
The component List Item
List Item (Item)
Inputs List (L) Base list Index (i) Item index Wrap (W) Wrap index to list bounds Outputs Item (i) Item at {i'}
Sometimes, we only need the first and last index of a list. We can zoom in on a
List Item
List Item (Item)
Inputs List (L) Base list Index (i) Item index Wrap (W) Wrap index to list bounds Outputs Item (i) Item at {i'} 0
, the new
output is then -1
and thus gives us the last item of the list.
Separate lists (Split List)
The component Split List
Split List (Split)
Inputs List (L) Base list Index (i) Splitting index Outputs List A (A) Items to the left of (i) List B (B) Items to the right of and including (i)
Subdivide lists (Partition List)
The component Partition List
Partition List (Partition)
Inputs List (L) List to partition Size (S) Size of partitions Outputs Chunks (C) List chunks
Extract a subset (Sub List)
The component Sub List
Sub List (SubSet)
Inputs List (L) Base list Domain (D) Domain of indices to copy Wrap (W) Remap indices that overshoot list domain Outputs List (L) Subset of base list Index (I) Indices of subset items
Remove items per index (Cull Index)
The component Cull Index
Cull Index (Cull i)
Inputs List (L) List to cull Indices (I) Culling indices Wrap (W) Wrap indices to list range Outputs List (L) Culled list
List Item (Item)
Inputs List (L) Base list Index (i) Item index Wrap (W) Wrap index to list bounds Outputs Item (i) Item at {i'}
Remove every nth item (Cull Nth)
The component Cull Nth
Cull Nth (CullN)
Inputs List (L) List to cull Cull frequency (N) Cull frequency Outputs List (L) Culled list
Remove random items (Random Reduce)
The component Random Reduce
Random Reduce (Reduce)
Inputs List (L) List to reduce Reduction (R) Number of items to remove Seed (S) Random Generator Seed value Outputs List (L) Reduced list
Remove items by using a mask (Cull Pattern)
The component Cull Pattern
Cull Pattern (Cull)
Inputs List (L) List to cull Cull Pattern (P) Culling pattern Outputs List (L) Culled list
Get the complement of a set
To get the complement
of a set, we need the set itself and the universal set ($A^C = U\backslash A$).
If the sets consist of or can be converted into Primitive Data Types, we can
use the component Set Difference
Set Difference (Difference)
Inputs Set A (A) Set to subtract from. Set B (B) Substraction set. Outputs Union (U) The Set Difference of A minus B
Item Index (Index)
Inputs List (L) List to search Item (i) Item to search for Outputs Index (i) The index of item in the list, or -1 if the item could not be found.
Cull Index (Cull i)
Inputs List (L) List to cull Indices (I) Culling indices Wrap (W) Wrap indices to list range Outputs List (L) Culled list
If we have the indices, but they occur multiple times, we can use Create Set
Create Set (CSet)
Inputs List (L) List of data. Outputs Set (S) A set of all the distincts values in L Map (M) An index map from original indices to set indices
List Item (Item)
Inputs List (L) Base list Index (i) Item index Wrap (W) Wrap index to list bounds Outputs Item (i) Item at {i'}
Cull Index (Cull i)
Inputs List (L) List to cull Indices (I) Culling indices Wrap (W) Wrap indices to list range Outputs List (L) Culled list
Dispatch items into two target lists (Dispatch)
The component Dispatch
Dispatch (Dispatch)
Inputs List (L) List to filter Dispatch pattern (P) Dispatch pattern Outputs List A (A) Dispatch target for True values List B (B) Dispatch target for False values
Before we can use Dispatch
Dispatch (Dispatch)
Inputs List (L) List to filter Dispatch pattern (P) Dispatch pattern Outputs List A (A) Dispatch target for True values List B (B) Dispatch target for False values
Evaluate (Eval)
Inputs Expression (F) Expression to evaluate Variable x (x) Expression variable Variable y (y) Expression variable Outputs Result (r) Expression result
Expression (Expression)
Inputs Variable x (x) Expression variable Variable y (y) Expression variable Outputs Result (R) Result of expression
Point In Brep (BrepInc)
Inputs Brep (B) Brep for inclusion test Point (P) Point for inclusion test Strict (S) If true, then the inclusion is strict Outputs Inside (I) True if point is on the inside of the Brep.
Is Planar (Planar)
Inputs Surface (S) Surface to test for planarity Interior (I) Limit planarity test to the interior of trimmed surfaces Outputs Planar (F) Planarity flag of surface Plane (P) Surface plane
Dispatch items into multiple target lists (e.g. filter by type)
As written above, Dispatch
Dispatch (Dispatch)
Inputs List (L) List to filter Dispatch pattern (P) Dispatch pattern Outputs List A (A) Dispatch target for True values List B (B) Dispatch target for False values
The following example shows how to filter a list of geometric objects into
separate lists for each type. The idea is to test each item with string comparison, whether it matches one of our criteria.
But before we can do this, we have to cast all objects into string format, which
is done by a Text
Text (Txt)
Expression (Expression)
Inputs Variable x (x) Expression variable Variable y (y) Expression variable Outputs Result (R) Result of expression Contains(x,y)
to test, if a string contains any of the
strings that we provide in a Panel
Panel
{
is present, to identify a point.{
is present, to identify a point. To
ensure that every object is matched with every string, we have to graft input
y.
After the custom evaluation, we can filter the list with a Dispatch
Dispatch (Dispatch)
Inputs List (L) List to filter Dispatch pattern (P) Dispatch pattern Outputs List A (A) Dispatch target for True values List B (B) Dispatch target for False values
Explode Tree (BANG!)
Inputs Data (D) Data to explode Outputs Branch 0 (-) All data inside the branch at index: 0 Branch 1 (-) All data inside the branch at index: 1
The task of filtering a list by type can also be achieved with a C# Script
C# Script (C#)
Inputs x (x) Script Variable x y (y) Script Variable y Outputs out (out) Print, Reflect and Error streams A (A) Output parameter A
Separate items into multiple lists by an integer pattern (Sift pattern)
The component Sift Pattern
Sift Pattern (Sift)
Inputs List (L) List to sift Sift Pattern (P) Sifting pattern Outputs Output 0 (0) Output for sift index 0 Output 1 (1) Output for sift index 1 0
and 1
) but with integers. The items at input L will be passed to the output that
corresponds with the provided integer. The ZUI can be
used to add outputs. Instead of just forwarding the items exclusively to the
corresponding list, their index at the other lists is filled with null items.
Remove null items
The simplest way to remove all null items from a list, is to use Clean Tree
Clean Tree (Clean)
Inputs Remove Nulls (N) Remove null items from the tree. Remove Invalid (X) Remove invalid items from the tree. Remove Empty (E) Remove empty branches from the tree. Tree (T) Data tree to clean Outputs Tree (T) Spotless data tree
Another possibility is to use Null Item
Null Item (Null)
Inputs Item (I) Item to test Outputs Null Flags (N) True if item is Null Invalid Flags (X) True if item is Invalid Description (D) A textual description of the object state
Cull Pattern (Cull)
Inputs List (L) List to cull Cull Pattern (P) Culling pattern Outputs List (L) Culled list
Group items that share equal properties
For bundling items that share an equal property, we find the components for this operation in the Grasshopper ribbon tab Sets.
For example, if we want to group lines by their length, we can calculate their
lengths and use Create Set
Create Set (CSet)
Inputs List (L) List of data. Outputs Set (S) A set of all the distincts values in L Map (M) An index map from original indices to set indices
Member Index (MIndex)
Inputs Set (S) Set to operate on. Member (M) Member to search for. Outputs Index (I) Indices of member. Count (N) Number of occurences of the member.
List Item (Item)
Inputs List (L) Base list Index (i) Item index Wrap (W) Wrap index to list bounds Outputs Item (i) Item at {i'}
Another way to receive a similar result is to use output M of Create Set
Create Set (CSet)
Inputs List (L) List of data. Outputs Set (S) A set of all the distincts values in L Map (M) An index map from original indices to set indices
Sift Pattern (Sift)
Inputs List (L) List to sift Sift Pattern (P) Sifting pattern Outputs Output 0 (0) Output for sift index 0 Output 1 (1) Output for sift index 1