A guide to organising your Grasshopper script

On this Page

As a project progresses, modelling requirements often evolve, making your Grasshopper script more cluttered and complex. To make handling and editing easier, it’s worth keeping your script as organized and tidy as possible from the beginning.

Investing just a small amount of upfront effort and time will pay off later, especially if you are adding more operations to an already complicated script. Not to mention, you would have a better time dealing and managing an organized script.

This is one of the most vital lessons I have learned over the years of using Grasshopper. There are a few tactics that I use to keep my canvas as neat as possible.

Using UI options to tidy your canvas.

While you can’t avoid a script that uses many components, you can use the several UI options in Grasshopper to make your script tidier.

A messy script can be very difficult to read, particularly when there are many crossing wires flowing into multiple components.

Container and Wire styles

The first step to tidying up a canvas, is to make use of containers and the various wire styles that Grasshopper has to offer. This alone can make your script much easier to read and your future self (and anyone else who reads your script) will thank you.

Let’s walk through an example of tidying up a script together. Consider the script below.

It’s a simple script but you can feel the encroaching mess if more components are added. The key to organizing your script is to work on one portion at a time, tidy it up, and then repeat the process for the rest of the script.

For this example, let’s tidy up the top left of canvas first.

To start, we can separate out the components into “areas”. These are normally the input and processing components.

Of course, the actual split will depend on your script but there should be some obvious “areas”. We are essentially looking for chunks of logic on the canvas that we can separate out.

Then, we look at tidying up the wires in-between these “areas”. To do that, we want to replace it with a container and use the "hidden" wire style (This sounds like a martial arts move)

Find for the appropriate data type container using the search bar of the component ribbon on the top. There should be a container for almost every data type that you use in Grasshopper. For this example, I need a “rectangle” container, so I'll just type “rectangle” in the search bar.

You can access the search bar by hitting the spacebar or double-clicking on a blank spot on the canvas

Then, just give the container a name for easier readability. You can do this by right-clicking and editing the name.

I like to leave the datatype in there and just add a “ : name“ after it, to be able to always see the datatype.

Then, I duplicate it and on the duplicated container, “right-click” and change the wire display to “hidden”.

This lets you drag the container anywhere in the script without showing the wire. If you select the container, you will be able to see the wire again.

Note: I know this seems like a lot of work but with the use of shortcuts, this process is very quick and the more you do it, the faster and easier it becomes.

After doing this for all the "areas", you get a script that looks something like this.

By using containers and the 'hidden' wire style, we have effectively modularized the script. Doing this clearly shows that the scripts is made of these three “areas”. Additionally, separating areas this way makes it easier to reuse them in the future.

If we then extend this logic to the entire script, this is what we get.

Like before, doing this clearly shows all working portions of the script which makes it easier to read and understand.

Using Scribbles to Label

We can make this even clearer by labelling each “area” of the script using the Scribble component. You can quickly create a scribble with a “~” followed by your label in the search bar.

Labeling each area provides a high-level view of the inner workings of the script and leaves breadcrumbs for anyone who needs to modify or read the script in the future.

Here’s what the script looks like now.

Using Groups and Colouring

If you have a large script with multiple types of 'areas', it may be helpful to color-code them. While it may be overkill for our current script, let's do it anyway to see a working example.

You can group components together by selecting them, right-clicking and then selecting “group”.

You can then change the colour of a group by right-clicking on the group and choosing your colour.

Now if I colour our script by their area type and label them, I end up with this.

Now, it is extremely clear what the components in the script are doing and the various 'areas' of the script.

Useful Plugins

Even if you are sold on the idea of organizing your script, it seems like the organization process is quite cumbersome. This is where plugins and tools can simplify the process and make it less of a chore.

There are many plugins out there that help you with this. You can find them on Food4Rhino but here are 2 of my favorite ones.

Snapping Gecko

SnappingGecko is a plugin that adds alignment guidelines to your Grasshopper canvas when you move components around, making it easier to neatly arrange your components. The plugin allows you to snap components to the lines for precise alignment.

Metahopper

Metahopper is a plugin that offers an extensive collection of components for manipulating Grasshopper components. While I won't go into detail about its many functions, it is a useful tool for enhancing your Grasshopper workflow and making it easier to tidy up your script.

The two components I use the most are the Enable/Disable Object component and the Group Toggle component. They both give me greater control over how to enable and disable components on my canvas.

Keyboard and mouse shortcuts

The best way to get faster at organising your script is with the use of mouse and keyboard shortcuts and the good news is that there isn’t that many of them.

Container and wire style shortcuts

To give you an example, let’s look at how I tidied up the script with containers and the “hidden” wire style. Here are the steps.

  1. Create a container.
  2. Name the container.
  3. Duplicate the container.
  4. Change the wire style on the duplicated container to “hidden”.

We can speed up steps 3 and 4 with the use of shortcuts.

Duplication

To quickly duplicate components in Grasshopper, holding “alt” and drag will give you a duplicate of the component.

Wire Styles and Right-click menu

To quickly access items in the right-click menu, you can “right-click” and hit the starting alphabet of the action you want.

To get to the “hidden” wire display. Just “right-click”, then hit “W” then hit “H” on the keyboard.

While Grasshopper offers several other shortcuts to speed up your workflow, I will delve deeper into them in another article.

Final Thoughts

Organizing your Grasshopper script from the beginning can save you a lot of time and effort in the long run. By using containers, wire styles, labeling, and groups you can modularize your script and make it more readable and easier to manage. Additionally, you can use plugins and shortcuts to further streamline the organization process and enhance your Grasshopper workflow.

While the process of organizing your script may seem cumbersome at first, the benefits of a tidy and well-organized script are well worth the effort. With that in mind, a working with a tidy Grasshopper canvas makes the scripting experience more enjoyable and efficient.

Thanks for reading

Braden