Grasshopper Hops

  • Intro
  • Why Hops
  • Installing Hops
  • Hops for Clusters (Hopable Definitions)
  • Running a Hopable Script
  • Overview of Using Hops to run Python Scripts
  • Creating a Python Script for Hops
  • Running a Python Script in Hops
  • Conclusion

Information

Primary software used Grasshopper
Course Grasshopper Hops
Primary subject Parametric Modeling
Level Intermediate
Last updated March 10, 2025
Keywords

Responsible

Teachers
Faculty

Grasshopper Hops 0/8

Grasshopper Hops

Hops allows you to reference definitions in a Grasshopper component and run external scripts you write in a code editor.

Hops can be best compared by external modules in programming. First you create a script, which works similarly to a cluster. After that you add a hop which references to your created definition. Hops can also be used to run external Python scripts in Grasshopper while letting you write them in a code editor which allows you to use debugging tools. We will show both examples in this tutorial.

Create your own hopable definition
Create your own hopable definition

Grasshopper Hops 1/8

Why Hopslink copied

When your knowledge about building Grasshopper scripts is increasing, it is easy to lose the control over your script because of its size. Grasshopper gives users several methods to make it easier to get an overview of what you made. Furthermore, some of these techniques can be used to publish, share and optimize your scripts. Generally speaking, there are three options:

  • Group your components;
  • Cluster components;
  • Hops.
Large scripts can be hard to follow
Large scripts can be hard to follow

This tutorial goes into the usages of hops. There are two main ways to use hops:

  • To incorporate definitions into components that we call clusters
  • To run scrips in Gasshopper that were created in a code editor

When using hops, there are several advantages and disadvantages to consider. 

Advantages

  • Hops can be computed parallel and therefore can be efficient in complex definitions;
  • Hops can cache solutions to use again;
  • Hops can use multiple processor cores in calculations;
  •  Hops can be executed using the GrasshopperPlayer function in Rhino;
  • Hops can use plugins from Grasshopper, like ladybug, anemone etc. as long as you have installed them.

Disadvantages

  • Hops may take more time to calculate initially;
  • Hops have less available input types. Vectors for example, are not available. Currently, McNeel advices to convert these datatypes to strings first (April, 2024);
  • Nested hops are currently not possible;
  • You cannot directly see a script when double-clicking on a hop, which makes it less traceable.

Grasshopper Hops 2/8

Installing Hopslink copied

First we need to install the Hop module. Open the Package Manager in Rhino and search for Hops. Install the latest version available. You will have to restart Grasshopper to use the plugin.
 

  • Open the Package Manager Rhino » Tools » Package Manager
  • Type and install Hops
  • Restart Rhino and Grasshopper
Install hops from the Package Manager
Install hops from the Package Manager

Grasshopper Hops 3/8

Hops for Clusters (Hopable Definitions)link copied

A key part of creating a Hopable Definition is defining the input and outputs of the component. To do this, there are specific Hops components you can use.

Instead of using standard Grasshopper input Parameters and Number Sliders, you will have to use the Hops contextual parameters in your script to create an input. Contextual Parameters can be found in the Util tab under Params. These components, will create the input field in your component. You can only have a Hops-supported input which means some input options are limited.

Inputs

Use Context Parameters
Use Context Parameters
  • Replace all inputs with contextual parameters Params » Util
Settings of Context Parameters
Settings of Context Parameters

By right-clicking on a Contextual Parameter, you can define an allowed range, like how you would do in a Number Slider. Rename the inputs and outputs according to their function.

  • Rename and define the range of contextual parameters RMB on contextual parameter

Outputs

Output the data
Output the data

To create an output, you use standard Grasshopper components from the Geometry and Primitive toolbars. Use the same type as the data you create. First, place and connect the correct Geometry or Primitive component, select it, and group it. Next, rename the group to RH_OUT:[output name]. You can output multiple objects by adding multiple groups.

  • Output the correct data Select output nodes » RMB on canvas » Group » RMB on group » Rename to RH_OUT:[output name]

Optional: Bake Output

Context bake your script
Context bake your script

Optionally, by adding the Contextual Bake component at the end of your script, the output of the script will be baked automatically when it is finished calculating.

  •  Add a contextual bake component at the end of your script Params » Util » Contextual Bake

Save Script

Save your hopable definition
Save your hopable definition
  • Save your definition GH Menu » Save document as

Grasshopper Hops 4/8

Running a Hopable Scriptlink copied

Open an empty canvas in Grasshopper and add the Hops component to the canvas.

A hop component
A hop component
  • Open an empty canvas
  • Add a Hops component Params » Util » Hops
Enter the location of the Grasshopper file.
Enter the location of the Grasshopper file.

Double-click on the Hops component and find the correct definition file you made in the previous step. This will load the script and create the inputs and outputs that you defined. You can plug in number sliders as the inputs and a panel to view the output.

  • Select the definition to hop Double-click hop » Find and select the saved hopable definition
Right click to change the component settings.
Right click to change the component settings.

By right-clicking on the node you will see multiple options:

  • Parallel Computing: Defines if the Hop is allowed to use multiple cores of your processor. This can be either faster or slower depending on the type of script;
  • Path…: Defines which path to use as definition;
  • Local Computes: The amount of solutions that already have been calculated. When you are inputting a range of numbers into the definitions, it sometimes make sense to change it to 6 pack. This allows Grasshopper to use multiple cores for different inputs and therefore increases the speed of the calculation. Important to note though, is that it is still not possible to use trees as input to be calculated parallel. Make sure you only use single lists. Simply said, every item in the list uses is handled as a separate operation in your processor;
  • Cache in Memory: Saves results temporarily in your computer memory;
  • Cache on Server: Saves results permanent for future use.

As you may notice, the speed of the solutions can increase drastically when you enable caching.

Running Hops in Rhino

It is also possible to use your Hop definition using the Rhino Command Line. 

Open GrasshopperPlayer
Open GrasshopperPlayer

First use the command GrasshopperPlayer and select the Hop definition.

  • Execute Rhino GrasshopperPlayer command Rhino » Commandline » GrasshopperPlayer
  • Select the hopable definition
Enter the required inputs.
Enter the required inputs.

Rhino now asks for data for the inputs of your definition. Enter the correct values.

  • Enter the asked values
  • Click on Enter
Receive the output.
Receive the output.

If the result of the script is not visible anymore after executing the definition, you probably forgot to add a Context Bake to the output of your script. You can also add a Context Print to send a message when the execution is completed.

Grasshopper Hops 5/8

Overview of Using Hops to run Python Scriptslink copied

Hops can also be used to run Python scripts that are written outside of Grasshopper. In the past, the Python component in Grasshopper did not have the same support tools that working in a code editor does, for example it did not have a debugger (a tool that notices and marks mistakes in your script). It also did not support importing external libraries like Numpy and Scipy. 

When the Script component was introduced, it alleviated some of these problems. For example you can now use Python 3 to write your code and you can import external libraries. However, the Script component still has some drawbacks. Running a Python script in the Script component can be slow, especially when handling large datasets and complex geometry. Additionally, there are still limitations on debugging your code. This is when Hops can be helpful. Hops allows you to run Python (and other scripts) outside of Grasshopper. This means the code will execute faster since it runs on an external server or environment and you get the benefits of debugging tools.

The Script component is a big improvement for running Python code in Grasshopper, but when you need to execute code quickly or want access to a full range of debugging tools, writing a Python script in a code editor like VS code and linking it with Hops may be a more appropriate option.
In addition to the information provided below, you can also reference the Rhino Developer guide on Hops at https://developer.rhino3d.com/guides/compute/hops-component/.

Getting Started

To learn how to install Hops, reference the previous section of the tutorial.

When using Hops to run a Python script you also need to use a code editor to write your Python code. Some options include VS Code (Visual Studio Code – Code Editing. Redefined) and PyCharm (PyCharm: The Python IDE for data science and web development by JetBrains).

The Hops Server

Hops uses flask and the ghhops-server libraries so you will need to install both in your development environment.

 

pip install flask
pip install ghhops-server

Writing Your Code

When writing the code for a component you need to follow the structure required and documented for Hops components. You can find the documentation on GitHub (https://github.com/mcneel/compute.rhino3d/tree/8.x/src/ghhops-server-py).

Grasshopper Hops 6/8

Creating a Python Script for Hopslink copied

We are going to create a script to calculate the Pythagoras Formula like we did in the example earlier. This time, however we will use Python to write a script and then use Hops to run this script.

First, import the dependencies. 

 

from flask import Flask
import ghhops_server as hs
import math

Then register the Hops application as middleware. Starting with the @hops.component decorate, decorate the function. The first argument passed to the decorator (“/pythagorasformula “) is the URL of this component on our server you will need this to link the Python code into Grasshopper. In this example, we will name the function pythagorasformula, we have two inputs (a and b) and one output (c). 

# register hops app as middleware
app = Flask(__name__)
hops = hs.Hops(app)

@hops.component(
    "/pythagorasformula",
    name="PythagorasFormula",
    description="with 2 inputs, solves Pythagoras' Formula",
    inputs=[
        hs.HopsNumber("a", "a", "the first number in the formula"),
        hs.HopsNumber("b", "b", "the second number in the formula"),
    ],
    outputs=[
        hs.HopsNumber("c", "c", "the output of the formula")
    ]
)
def pythagorasformula(a, b):
    c = math.sqrt(a**2 + b**2)
    return c

If you are defining multiple Hops components, you can continue by declaring a new decorator and then writing your next function. 

 

Finally, end the script by running the Hops server.

if __name__ == "__main__":
    app.run()

Save the code to a file called app.py in the python file, navigate to the file location in your terminal, and run it using python:

Python app.py

NOTE: The messages that confirm your server is running also tell you the address of the server, copy this to put into the hops component in Grasshopper. The server will say “Running on “ and then the address, for example http://127.0.0.1:5000 or localhost:5000

Grasshopper Hops 7/8

Running a Python Script in Hopslink copied

NOTE: Make sure you have run your Python script to start the server. You must do this in the terminal (see the final step of the previous chapter.

You will continue in grasshopper. Open an empty canvas in Grasshopper and add the Hops component to the canvas.

A hop component
A hop component
  • Open an empty canvas
  • Add a Hops component Params » Util » Hops
Enter the location of the function on the server.
Enter the location of the function on the server.

Double-click on the Hops component and enter the URL of the component on our server. Remember, this is the address of the server we copied plus the first argument from the @hops.component decorator. In the example images, the script is running at http://localhost:5000/pythagorasformula

  • Select the definition to hop Double-click hop » enter the URL of the component on the server
Use your Hop to calculate the Pythagoras formula
Use your Hop to calculate the Pythagoras formula

When you select okay, the component will load with your defined inputs and outputs. Then you can connect the inputs and outputs. In this case, we will connect two number sliders. One for input a and one for input b. Then we can connect the output to a panel to see the result of the calculation.

  • Add two number sliders as inputs and a panel to read the output.

Grasshopper Hops 8/8

Conclusionlink copied

Through this tutorial you learned how to use Hops to cluster components which also allows you to use all of the options Hops offers like parallel computing. You also reviewed how Hops can be used to run Python code that you create using a code editor for when need to execute code quickly or want access to a full range of debugging tools.