The Hops Component

Overview

/images/hops-overview.png

Hops is a component for Grasshopper in Rhino 7 and Rhino 8 WIP for Windows. Hops adds external functions to Grasshopper. Like other programming languages, functions let you:

  • Simplify complex algorithms by using the same function multiple times.
  • Eliminate duplicate component combinations by placing common combinations in a function.
  • Share Grasshopper documents with other team members.
  • Reference Grasshopper documents across multiple projects.
  • Solve external documents in parallel, potentially speeding up large projects.
  • Run asynchronously on long running calculations without blocking Rhino and Grasshopper interactions.

Hops functions are stored as separate Grasshopper documents. The Hops component will adapt its inputs and outputs to match the function specified. During calculation Hops solves the definition in a separate process, then returns the outputs to the current document.

How to use Hops Windows

Installing Hops for Windows:

There are a few ways to install hops on your machine.

  1. Install Hops (This will launch Rhino)
  2. Or, type PackageManager on the Rhino command line.
    1. Then, search for “Hops”
    2. Select Hops and then Install
/images/gh-hops-package-manager.png

Create a Hops Function

Hops functions are Grasshopper documents with special inputs and outputs.

/images/hops_simple_function.png

Defining Inputs

Hops inputs are created using the Get Components. The available Get components in Grasshopper are found under Params Tab > Util Group:

/images/hops_context_getters1.png

The name of the component is used for the name of the Hops input parameter. So, in the example above, we have three Get Number components with names A, B, and C. Each of these Get components become input parameters when Hops compiles the definition.

/images/hops_getter_inputs.png

Each Get component has a context menu (right-click) with various settings.

/images/gh-hops-get-component-menu.png
  • Component Name - This is the name that will be assigned to the input of the Hops component.
  • Prompt - This input will be the tooltip that is displayed when you hover over this parameter on the Hops component.
  • Enable/Disable - Enable or disable this component.
  • At Least - This is only used for the Grasshopper Player and will define the minimum number of values to accept for this input.
  • At Most - This will define the maximum number of values to accept for this input (Default = 1). If this value is set to 1, the Hops component will treat this input as Item Access. However, if this value is more than one (or unset) Hops will treat this input as List Access.
  • Minimum & Maximum - These optional inputs are only used for the Grasshopper Player and will clamp numeric inputs to these bounds.
  • Presets - This optional input is only used for the Grasshopper Player and are only found on the String, Integer, and Number Get components. This dialog allows you to set a list of predefined options which will be displayed to the user via the command line prompt.

Defining Outputs

Hops outputs can be defined using the Context Bake or Context Print components. The name of the input parameter on either of the Context components will be used as the name of the output parameter when Hops gets computed.

/images/hops_getter_outputs.png

Use the Hops component

  1. Place the Grasshopper Params Tab > Util Group > Hops component onto the canvas.
  2. Right-click the Hops Component, then click Path.
  3. Select a Hops Function. Note: this can be a Grasshopper definition on your computer, on a remote computer, or a REST endpoint.
  4. The component will show the inputs and outputs.
  5. Use the new component like any other Grasshopper component.
/images/hops_multiplyadd.png

A note about Hops for macOS users

The Hops component works in tandem with a local instance of a Rhino.compute server which, typically, is spun up whenever you launch Grasshopper. However, this server will not run on macOS which means there are two other options for you to consider. You can:

  1. make a REST API call to a remote server running on Windows.
  2. make a REST API call to a python ghhops_server running locally.

The first option (making a call to a remote Windows server) will require some setup modifications to the remote machine. For more information on how to setup a remote server, checkout the section on Remote Machine Configuration.

The second option (making a call to a local python server) is covered in more detail in the section called Calling a CPython Server.

Hops Settings

Application Settings

The Hops settings control how Hops runs on an application level. It is available through the Grasshopper File pulldown > Preferences.

/images/gh-hops-preferences.png
  • Hops-Compute server URL - List the IP address or URL of any remote machines or Compute servers.
  • API Key - The API key is a string of text that is secret to your compute server and your applications that are using the compute API e.g. b8f91f04-3782-4f1c-87ac-8682f865bf1b. It is optional if you are testing locally, but should be used in a production environment. It is basically how the compute server ensures that the API calls are coming from your apps only. You can enter any string that is unique and secret to you and your compute apps. Make sure to keep this in a safe place.
  • Max Concurrent requests - Used to limit the number of active requests in asynchronous situations. This way hops doesn’t make thousands of requests while the original request is being processed.
  • Clear Hops Memory cache - Clears all previously stored solutions from memory.
  • Hide Rhino.Compute Console Window - Hops will solve in the background, but showing the window can be helpful for troubleshooting.
  • Launch Local Rhino.Compute at Start - Use this for remote machines when Compute needs to start before any requests are sent.
  • Child Process Count - Used to limit the number of requests for additional parallel processes. May want to set this to the number of cores available.

Note: As of Rhino version 7.13, the active model tolerances (ie. absolute distance and angle tolerances) are passed from Hops to the running instance of Rhino.compute as part of the JSON request.

Component Settings

Right_click on the Hops component to select any number of options that control how Hops runs.

/images/gh-hops-component-settings.png
  • Parallel Computing - Pass each item to a new parallel node if available.
  • Path… - Add the location of the GH function to be solved. This may be a file name, IP address or URL.
  • Show Input: Path - Makes the Path an input on the component so Path can be set through the GH Canvas.
  • Show Input: Enabled - Shows an Enabled input that runs the component based on a True or False Boolean value.
  • Asynchronous - The user interface will not be blocked while waiting for a remote process to solve and the definition will be updated when the solve is complete.
  • Cache In Memory - Previous solutions are stored in memory on the local machine to improve performance if the same inputs were previously calculated.
  • Cache On Server - Previous solutions are stored on the remote server to improve performance. Currently available on Remote Hops services only.

Remote Machine Configuration

By default Hops will use your local computer to solve Grasshopper functions. However, it is possible to setup remote computers (ie. servers) or virtual machines for Hops to call.

In order to make API calls to a remote machine, please follow this guide on setting up a production environment.

Calling a CPython Server

Use Hops to call into CPython. Some advantages of this component:

  1. Call into CPython libraries including Numpy and SciPy
  2. Use some of the newest libraries available for CPython such as TensorFlow.
  3. Create re-usable functions and parallel processing.
  4. Supports real debugging modes including breakpoints.
  5. Full support of Visual Studio Code.
  6. Other applications and services that support a Python API can also use the libraries included here.
  7. The Hops component attempts to detect when inputs and outputs have changed on a server and will rebuild itself.

Getting started with CPython in Grasshopper

This Python module helps you create Python (specifically CPython) functions and use them inside your Grasshopper scripts using the new Hops components.

Required:

  1. Rhino 7.4 or newer.
  2. CPython 3.8 or above
  3. Hops Component for Grasshopper
  4. Visual Studio Code highly recommended

Video Tutorial:

This module can use its built-in default HTTP server to serve the functions as Grasshopper components, or act as a middleware to a Flask app. It can also work alongside Rhino.Inside.CPython to give full access to the RhinoCommon API.

Frequently Asked Questions:

Can you nest Hops functions within other functions?

Yes, it is possible to nest Hops function within other functions. This is called recursion and the default recursion limit is set to 10.

Does it cost money to use Hops?

Hops is free to use.

Can Hops be used with Grasshopper Player to make commands?

Yes, Hops functions can use Context Bake and Context Print components to create Rhino commands in Grasshopper Player.

Does Hops support parallel processing?

Yes, Hops by default will launch a parallel process for each branch of a datatree input stream.

What input and output types does Hops support? (It supports all common types, ask about other ones if you need them)

Hops passes standard Grasshopper data types (Strings, Numbers, Lines, etc…). For other datatypes such as images or EPW weather files use a string for the file name so that the external function might also read in the same file.

Can plugin components run in Hops Functions?

Yes, all the installed Grasshopper plugins can run within a Hops Function.

Can this be used for extremely long calculations within a function?

Yes, each Hops component has an option to solve asynchronously. The user interface will not be blocked while waiting for a remote process to solve and the definition will be updated when the solve is complete. Hops will wait for all function calls to return before passing the outputs to the downstream components.