This tutorial provides a step-by-step guide for generating designs in the Generative Platform using a Grasshopper file. It creates a simple torus and measures its volume as an example.

Final outcome of the tutorial.

You can also interact with the finished project in the app.

Prerequisites

Windows

This connector is currently supported for running on Windows only.

If you’re on another operating system and want to use the connector, it is possible to do so with some further setup (e.g. using a virtual machine) - get in touch to find out more.

Rhino

1

Install Rhino 8 or above

Download and install Rhino 8 or above and make sure you have an active licence.

2

Install ASP.NET 7.0

Rhino Compute, which we use to communicate with Rhino, requires ASP.NET Core Runtime 7.0. Download and install it if you don’t currently have it.

You can see what versions of ASP.NET you currently have by running dotnet --info in a Powershell terminal.

3

Install Hops

Install the Hops plugin for Grasshopper, so that a Rhino Compute server starts in the backgroup each time Grasshopper is started.

Python

The Grasshopper connector is currently provided as a Python package.

This means that you also require Python and an IDE (a code editor). See the Setup page if you’re missing these.

Create a basic Grasshopper file

Create a new Grasshopper file and define a function which describes the engineering system you want to explore over.

Define the inputs using uniquely named Get Number, Get Integer, Get Boolean etc. nodes, which by default are located in the Params tab under the Utils dropdown. Give each input a default value, for example with a slider node for a number.

Define the outputs using uniquely named Conext Bake nodes. Make sure you the mesh the geometry before outputting it.

For example, implement the below in Grasshopper to create a torus and calculate its volume, or download the Grasshopper file.

Grasshopper definition to create a torus and calculate its volume.

See more information about the Grasshopper file requirements to be compatible with the Generative app.

Connect the Grasshopper file to the app

Keep Grasshopper open (or start it if it’s not running already).

Initialise a repository

To create a Generative Function from your Grasshopper file, you need somewhere to store and run the code. This is simply a folder anywhere on your computer that has access to Python.

The Python code you’ll need is only 3 lines - simply to define the location of the Grasshopper file.

1

Create an empty folder

If you are using an IDE (code editor), you can probably do this step there.

We recommend you do not create a venv, which some IDEs will do by default when making a new project, unless you’re already comfortable with virtual environments.

If you want to manage different Python packages per repository, we recommend you use a package manager - see the ‘Advanced’ track in the Setup guide for how to set one up.

2

Install the Generative packages

Install Generative packages generative-core, generative-server and generative-server-grasshopper-connector from pypi.generative.vision.

Open a terminal window, navigate to the folder you created, and run:

pip
pip install --extra-index-url https://pypi.dev.generative.vision/simple generative-server generative-server-grasshopper-connector
python -m generative.server --version

If this is successful, the version of generative-server-grasshopper-connector will be printed.

If you’re not using a virtual environment (venv), this installs Generative packages globally - so you’d only need to do this once per machine. If you are using a venv then you will need to install generative server inside the venv.

Create a Generative Function

Copy the below to a Python file in the folder or repository that has access to the Python packages, defining the location of the Grasshopper file relatively where your terminal is running (normally the root of the repository).

generative_function_torus.py
from generative.plugins.server.grasshopper.function import GrasshopperFile

class MyFunctionName(GrasshopperFile):
    file_path = "relative/path/to/grasshopper/file.gh"

Connect to the app

Great! Now you have finished writing a Generative Function, the next step is to connect to the app to start generating designs.

1

Start up a local function server

Run the following command from a terminal at the root of your repository or in the folder your Generative Function is in:

python -m generative.server start --no-reload

When you make changes to your function, manually stop the server (e.g. Ctrl-C in Powershell) and run the above command again. If you want the server to automatically restart when you make changes to your function, you can remove the --no-reload option or use --reload, but on Windows this is known to not work as expected so we recommend using --no-reload.

To learn more, see the concepts section.

2

Login to the app

Account is required to proceed. If you haven’t already, sign up at generative.vision.

Open app

3

Create an empty project

Create and navigate to an empty project. Under the ‘Experiment’ tab, your local function server will be automatically detected if it’s running on port 3000.

If your function server is not detected, check the logs in your terminal where you’re running the server. If the server started correctly, you should see a link, which will take you the server’s API docs page.

Generating your first designs

You should now have a project open in the app connected to your new Generative Function.

1

Set up an experiment

Before you start generating designs, you need to constrain the parameters exposed by your Generative Function by giving them values.

For example, add the cross section radius and path radius parameters to vary from 0.5 to 1, and 1 to 4. Leave the other parameters at their default values from the Grasshopper file.

Experiment is set up and ready to generate designs

2

Click 'Generate' to start

Once you have some values set, you can start generating data for all parameters specified in your Generative Function.

The algorithm will try to work within the constraints you set and generate data that you can visualise next.

Visualising generated data

Navigate to the ‘Discover’ tab. This is where you can visualise the generated data and curate it to find new insights.

Either view the data in the curated Insight, or, Add a new insight tab and follow the instructions to create a visualisation of the latest experiment across cross section radius, path radius and volume parameters.

Add another view by clicking the + button on the right hand side, and add the geometry parameter.

View results on the Discover page

The first time you visualise data, you may need to tell the system how to display the geometry parameter. If you see a tooltip saying “Unable to auto detect display type for X parameter(s)”, as shown below, click the review button and select geometry.

The prompt to select display type

Setting the visualisation type of the geometry parameter

This is a very simple function, but you can already see that the volume increases slightly as the cross-section radius increases, and increase strongly as the path radius increases. You can also see the visualisation of geometry within the app.

Finished project

Congratulations, you finished the tutorial!

To see the finished project:

  1. Go to the app
  2. Open a copy of the tutorial project ''
  3. Navigate to the ‘Discover’ tab to view generated designs

More learning

Now you’ve run your first experiment, if you want to learn more, check out the key concepts for using the Grasshopper connector.