How to Remove Duplicate Curves in Grasshopper

How to Remove Duplicates Curves in Grasshopper - Step by Step Tutorial
Contents

Duplicate geometries have been a problem in CAD software since the days of AutoCAD. Grasshopper is not immune to this issue – it’s easy to accidentally generate duplicate curves in Grasshopper and in this post I’ll share how to remove them in 3 easy steps.

To illustrate, let’s consider a simple scenario:

Example Problem:

It’s easiest explained with a practical example, so let’s assume this simple scenario:

We’ve created a series of adjacent rectangles in Grasshopper and then exploded the rectangles to pick only the long sides of the rectangles.

How to Remove duplicate curves in Grasshopper - Tutorial Step 1

Now by design, we are now dealing with two overlapping curves between every two rectangles that touch.

Now let’s learn how to remove the duplicate curves and only keep one of each!

How to Remove the Duplicate Curves

Removing duplicate curves in Grasshopper involves identifying unique curve midpoints, culling duplicates through the ‘Cull Duplicates’ component, and using indices to select and retain original curves.

Now let’s break that down step by step.

Although there’s no specific ‘Remove Duplicate Curves’ component in Grasshopper, we can use the ‘Cull Duplicates’ component instead.

You’ll find the component in the ‘Vector‘ component tab, in the ‘Point‘ group.

Adding the Cull Duplicates component in Grasshopper

To add it quickly, double-click where you want the component to appear, starting typing ‘cull duplicates’ and select the first result.

Quick-Adding the Cull Duplicates component in Grasshopper

The Cull Duplicates Component

Let’s take a closer look at this component. The component inputs are:

  • The Points (P)
  • and the Tolerance (T)
Inputs and Outputs of the Cull Duplicates component

As the position in the ‘Points’ group would suggest, this component removes duplicate points, and points only.

Also keep in mind that this component will only remove duplicates in a list – so if you are connecting a data tree with several branches, the duplicates will only be removed within each individual branch!

In many cases, we’ll have to flatten the input of points we want to clean up to make sure all points are considered.

The Tolerance (T) defines the distance beyond which two points will be considered duplicates. If two points are closer together than defined in the tolerance, Grasshopper is going to consider them duplicates. The Tolerance (T) comes with a default value of 0.1, which works for most cases.

Now how can we use this component to remove our duplicate curves?

The answer lies in the outputs. Let’s take a look. The outputs are:

  • The Culled Points (P)
  • The Indices (I) of the Culled Points
  • and the Valence (V), or the number of input points represented by the output points.

The first output Culled Points (P) is clear: it contains the original point list without the duplicates.

The Indices (I) output is the crucial output we need: It represents the indices of all the points that remain after the duplicates have been culled (removed). With this index information, we can process any other list of the same length – also curves!

The Valence (V) is a nifty feature, but I’ve never found good practical use for it in 10 years of using Grasshopper.

Setting the Cull Duplicates Option

But there’s more to this component than just its inputs and outputs! Below the component name, there is a black bar with the text ‘Average‘. Some Grasshopper components allows us to specify an additional option.

To change it, right-click on the name of the component. In the menu that appears, we’ll see three option to select from:

  • Leave One
  • Cull All
  • Average
Controlling the Culling Option

Leave one” will keep one of the duplicate points. “Cull all” will delete all duplicate points. “Average” (the default) will return a new point located at the average position between all the duplicate points within the tolerance.

In most cases, we’ll want to use the “Leave One” option. This ensures we keep one element and just remove any duplicates.

Step-by-Step Tutorial

Now let’s see how to implement the Cull Duplicates component to remove the duplicate curves in our Grasshopper script.

Step 1: Convert curves to midpoints

The Cull Duplicates component only works on points, so the first thing we need to do is create a representative point for each curve. We are going to do so by getting the curve’s midpoint.

Getting the curve’s midpoint guarantees that any two duplicate curves will also generate overlapping points.

Let’s use the ‘MidPoint‘ component. Type ‘curve middle’ into the component search bar to add it.

Quick-Adding the Curve Middle component in Grasshopper

Step 2: Use the ‘Cull Duplicates’ component

Now let’s add the Cull Duplicates component. Let’s connect our list of curves to the Curve Middle (MidPt) component, and that output to the Points (P) input of the Cull Duplicates component.

Step 3: Setting the culling option to ‘Leave One’

Let’s right-click on the component and select ‘Leave One’ from the option list.

How to Remove duplicate curves in Grasshopper - Tutorial Step 2

Step 4: Apply indices to select unique curves

Now let’s learn how to leverage the Indices (I) output.

The Indices ‘I’ output contains a list of all the indices of the points that remain after removing duplicates.

So to apply it to our curves, all we need to do is use a ‘List Item (Item)‘ component. You can find ‘List Item’ in the ‘Sets‘ component tab, in the ‘List‘ group.

List Item will return all the items in a list that have the indices we specify in the Index (I) input. So if we connect the indices of the culled duplicate points here, we can select all the source curves that match the pattern.

The List (L) we want to select items from is the flattened Curves list.

How to Remove duplicate curves in Grasshopper - Tutorial Step 4

And there we have it!

We successfully removed all the duplicate curves in our Grasshopper script by leveraging the ‘Cull Duplicates’ component. As the two panels below show, we started out with 12 curves and once the duplicates are removed, we are left with 7.

How to Remove duplicate curves in Grasshopper - Tutorial Step 5

Concluding thoughts on Removing Duplicate Curves in Grasshopper

By following these steps, you’ve learned a straightforward method to clean up your Grasshopper scripts by removing duplicate curves. This technique is versatile and can be applied to any type of geometry, provided you can generate a representative point for duplicate detection.

Culling duplicates is just the beginning—Grasshopper offers a vast landscape of possibilities to explore. If you’re eager to dive deeper and fast-track your learning, consider enrolling in “Grasshopper Pro.” This comprehensive course is designed for architects and teaches everything from the basics to advanced strategies to elevate your design skills.

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