How to Use Stream Filter in Grasshopper to Select Data Streams

Contents

Parametric design is all about flexibility. In Grasshopper, we typically control parameters using Number Sliders or manual data entry, which limits us to defining a single item at a time. However, there are times when we need to select an entire data set from a range of options. This is where the Stream Filter component in Grasshopper comes in.

The Stream Filter component allows us to filter one of multiple input streams using a number, acting like a multi-mode switch that determines which connected data stream becomes the output.

Where to Find the Stream Gate Component

To begin, let’s add the Stream Filter component to our Grasshopper canvas. You can find it under the ‘Sets‘ component tab, grouped under ‘Tree‘.

Adding the Stream Filter component in Grasshopper from the tabs

To add the component using the component search bar, double-click anywhere on the Grasshopper canvas and type ‘stream filter’. Click on the component to add it.

How to add the Stream Filter in Grasshopper

Inputs and Outputs Explained

By default, the Stream Filter component has three inputs:

Inputs and Outputs of the component explained
  • the Gate (S): This is a number input that controls which stream to forward to the output. This is the ‘switch’ that controls the output.
  • Stream 0 (0) and Stream 1 (1): These two inputs are for the data streams to choose between. We can connect any data type, as well as any data structure: from single items to complex tree branches.

The single output is the Filtered Stream (S). In brackets, the output will display the number of the selected input stream. S(1) for example, means that the data stream from input 1 has been selected.

Basic Stream Filter Setup

Here’s what a basic Stream Filter setup with two data streams looks like:

Example Setup of Stream Filter

Connect two data streams to the 0 and 1 inputs. A data streams is any kind of data (text, points curves, etc.). It can be a single item or a complex data tree of items.

Then add a Boolean Toggle and connect it to the Gate (G) input. Since Boolean Values (True and False) correspond to 0 and 1, this toggle provides a straightforward way to control which output the data stream should be directed to. If the toggle is set to ‘False(=0), input stream 0 will be the component’s output, if set to ‘True(=1) input stream 1.

Adding More Data Streams

To filter among more input streams, add more input options. Zoom in to the Stream Filter component until you see small plus and minus signs.

(If this is the first time zooming up close to the component, you’ll see a popup message explaining how you can add or remove outputs.)

Adding more output options to a component

Click on the plus icon to add as many additional stream inputs as needed. The additional inputs will automatically be numbered in sequence.

Since there now are more than two input options to choose from, we can no longer use the Boolean Toggle to select the output. Instead, use a Number Slider, with a range matching our output options. For example, if you have four outputs, set the slider range from 0 to 3.

Example of Stream Filter with multiple outputs

In the example shown above, the Gate input is the number 1, and the data from the input Stream 1 is directed to the output. In my example above, the input Stream 1 contains a list of three curves, as displayed in the Panel.

Why Use the Stream Filter Component?

If you are familiar with the List Item and the Value List components, you might be wondering why you can’t simply use those instead of the Stream Filter component. The reason is simple: Both the List Item and the Value List component can only select a single item.

The Stream Filter on the other hand allows us to select an entire data stream, regardless of how many items and branches it contains, or what kind of data it contains. The Stream Filter is therefor your component of choices if you want to select among different data trees.

Concluding thoughts

The Stream Filter component is an essential tool for managing data flows in Grasshopper scripts, making it easy to select among different data streams without manually reconnecting components. With the ability to add multiple outputs, you can efficiently manage complex data streams in your projects.

Happy designing!

Article by

Picture of Thomas Tait
Thomas Tait
Architect at Snøhetta and Head Instructor @ Hopific (or, in plain English, I help designers use Grasshopper to supercharge their designs.
Ready to Dive into Grasshopper? Grab Your Free Ebook!

Accelerate Your Learning and Get Up and Running Quickly.

More Great Reads