hopific logo blue

Offset Curve to Both Sides in Grasshopper – A Step-by-Step Guide

Grasshopper Offset to both sides - Featured Image
Quick links

Offsetting curves is a fundamental command in any design software. While Grasshopper has an offset curve component, it can’t offset to both sides. In this comprehensive guide we’ll delve into the process of creating a custom component that enables you to offset a curve to both sides in Grasshopper. By the end of this step-by-step tutorial you’ll have your very own custom offset component, an indispensable tool in your Grasshopper toolbox!

So, without further ado, let’s get started!

Creating a Custom Offset-to-Both-Sides Component from Scratch

Grasshopper’s ‘Offset Curve’ component doesn’t have a setting that allows us to offset the curve to both sides. While we could search for a Grasshopper plugin and install it, it’s easier to create a custom component ourselves, that does exactly what we want.

Here’s how we are going to do it:

  1. Create two offsets, one to either side of the curve.
  2. Extract the end points of the resulting offsets
  3. Connect the end and start points of the offsets with a line component.
  4. Join the offset curves and the lines to create a closed curve.
  5. Create a ‘Cluster’ from the created components and save it as a custom component.

Let’s go through these steps one by one.

Offset Curve to Both Sides – Step-by-Step Tutorial

We are going to start by referencing a set of curves from Rhino. These will be our testing curves, after all we want our script to work in a variety of scenarios.

I’ll reference the curves to a Curve Container component.

Setting up the Offset Curve Components

Next, let’s add two Offset components. To add the component, double-click onto an empty spot on the Grasshopper canvas and type ‘Offset’. The ‘Offset Curve’ component will be the first result. Select it to drop it to the canvas.

Adding the Offset Curve Component in Grasshopper

Now let’s connect our curves the the Curve (C) input of both ‘Offset Curve’ components.

Let’s add a Number Slider that we’ll use to define the offset distance. To add a number slider with a value of 1.5, I’ll double-click onto the canvas and type “1.50”, followed by ‘Enter’.

Grasshopper will create a number slider with the value 1.50.

We’ll connect this value to the Distance (D) input of both our ‘Offset Curve’ components.

Adding two offset curve components in preparation for offsetting it to both sides

Inverting the Offset Direction to Offset the Curve to Both Sides

As we would expect, we get two identical offsets. The next step will be to invert the offset direction of the second Offset Curve component.

To do that, we’ll add an expression to change the number slider value to a negative number.

We right-click on the Distance (D) input of the second Offset Curve component and go to ‘Expression’.

Let’s type “-x” into the blank field. “x” is a placeholder for any number input in Grasshopper components. This means that our number slider value of 1.50 will become -1.50.

As soon as we confirm with “Commit Changes”, the preview will show that the offset is now in fact on both sides of the curve.

Adding an expression to invert the offset direction and offsetting the curves to either side

Before we continue, let’s think of what parameter we want to be able to define for our offset. For an offset to one side, a simple number slider makes sense, it describes the offset distance from the original curve to the offset curve. But since we offsetting in both directions, the “thickness” of our offset is now 2 x 1.50.

Using Expressions to Define the Width of the Double-Sided Offset

To make the number slider value the total width of our double-sided offset, let’s edit the expressions for both components.

We’ll put “x/2” into the expression editor of the first offset component, and change our “-x” expression to “-x/2“.

Now the slider value defines the width of the final offset.

Adjusting the offset amount with expressions

The next step is to connect the ends of our two offsets to create a closed curve. We’ll create a simple line between the start and endpoints of the curves.

Creating a Closed Curve by Connecting the Offsets

Let’s type ‘End Points’ into the component search bar and add the ‘End Points’ component. This component will simply output the start and end points of the input curve in separate outputs. We’ll need two of these, one for each offset curve.

Adding the End Points Component in Grasshopper

Now let’s connect them.

Let’s add a ‘Line’ component. Double-click on the canvas to activate the component search bar and type “line”. Make sure to pick the result that says “Create a line between two points” when you hover over it. The first result is also called ‘Line’ but it’s simply a data container.

Adding the Line Component in Grasshopper

We’ll need two of these, so let’s click and drag on the ‘Line’ component and tap ‘ALT’ on the keyboard to create a copy.

The ‘Line (Ln)’ component is straight-forward: it will create a line by connecting two points defined by the ‘A’ and ‘B’ inputs.

We want to connect both start points and both end points, so we need to connect both ‘S’ outputs of the ‘End Points’ components to the ‘A’ and ‘B’ inputs of the ‘Line’ component respectively.

The line should now appear in the preview, connecting one side of the offset curves. Let’s repeat the same for the end points ‘E’.

Creating the end line segments to join the offset curves on both sides

We now have every element in place, and the preview in the Rhino viewport shows a closed curve.

But the preview can be misleading: in Grasshopper we are still dealing with four separate curves: the offset curves to both sides and the lines at each end. Let’s join the curves to create a single closed curve.

Joining the Curve Segments to Create a Single Closed Curve

Let’s add a ‘Join Curves’ component. Add it through the component search bar as shown below, or by going to the ‘Curve’ component tab. You’ll find the ‘Join Curves’ component in the ‘Util’ component group on the right.

Adding the Join Curves Component in Grasshopper

Great! Now let’s connect our curve segments! We’ll start by connecting the two line segments we just created.

To add multiple data streams to the same input, hold ‘Shift’ until the connection is made. A small green arrow and a plus symbol will let you know that the wire will be added to the existing connections, instead of replacing them.

Next, we’ll connect the output of both ‘Offset Curve’ components.

We now have a closed curve for each curve we offset two both sides!

Joining the curves offset to both sides and their end segments

This setup allows us easily turn the closed curves into a surface as we develop our scripts.

Since it’s likely that we’ll use this sequence of components in several different scripts, let’s create a “User Object” or custom component from this cluster.

The way to save a series of components as a User Object, is to create a ‘Cluster’ first, and then saving the cluster as a User Object.

Creating a Cluster from the Components

Let’s start by defining what inputs our custom component should have. We’ll need an input for the curves to offset and one to define the offset distance. The output will simply be the closed, offset curve.

Let’s add a data container for these inputs and outputs and add them to the script. This will make turning it into a cluster much easier.

I’ll insert a ‘Curve’ container and ‘Num’ container at the beginning and reconnect the ‘Offset Curves’ components and the ‘Number Slider’. Instead of re-creating the connections, hold down ‘CTRL’ + ‘SHIFT’ and then drag the wires from the current ‘Curve’ output to the new one. Repeat for the ‘Num’ component.

We’ll add one further ‘Curve’ container at the end of our script. Now we are ready to create our cluster.

Adding container components in preparation for the cluster

Select all the components except the first ‘Curve’ container, the ‘Number Slider’ and the final ‘Curve’ component. All the wires connected to components that are not selected, will become the inputs and outputs of the cluster.

Now press the middle mouse button anywhere on the Grasshopper canvas and click on the brown box icon on the very top of the round menu that appears. The tooltip will say ‘Cluster’.

Once you click it all the selected components will be compressed or “boxed” into a component. The connections to the remaining components will remain.

Creating a cluster in Grasshopper

To make the cluster more user-friendly, let’s right-click on the middle of the component and change the name to something more descriptive in the top text field. I’ll call it ‘OffsetBothSides’.

Changing the name of a component or cluster in Grasshopper

We can also change the name of the inputs to make it clear what they are. Change the ‘Num’ input to ‘Distance’ or simply ‘D’ by right-clicking on the input and typing the name into the top text field.

Perfect! The cluster is now complete!

Saving the OffsetBothSides Cluster as a User Object

To be able to add it to any future script we create, select the component and go to File / Create User Object…

Turning a cluster into a User Object in Grasshopper

In the menu that pops up, we can change the name of the custom component, a description and even a icon.

Once you confirm, the custom component will be saved in a new component tab that will be automatically added to component toolbar.

It will also appear in the component search bar if you type its name!

Congratulations! You have successfully created a custom “offset curve to both sides” component!

Final thoughts

You’ve made it to the end of this guide, and you should now have a solid understanding of how to create a custom component that will offset a curve to both sides in Grasshopper. This component is a versatile tool that can be used in a variety of scripts, making your work in Grasshopper more efficient and streamlined.

Make sure to keep an eye on the data structure of the input to the custom component and make adjustments where needed!

Keep exploring, keep learning, and most importantly, have fun with Grasshopper!

Happy designing!

Like this article?
Share on LinkedIn
Picture of Thomas Tait
Thomas Tait
Lead Designer 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.