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 .NET 7.0.x

If you don’t already have .NET 7.0.x, download and install it.

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

Look for AspNetCore, NetCore and WindowsDesktop and check if any versions matching 7.0.x are present for all of them.

The above link will take you to a direct download for .NET Runtime SDK 7.0.20 for Windows 64. You can also see here the other available versions for 7.0.x. Use the appropriate installer for the latest patch for version 7.0 of the SDK for your machine.

.NET Runtime 7.0.x is required because for Rhino Compute, which we use to communicate with Rhino. Any newer versions of .NET like 8.x or 9.x will, at time of writing, not work with Rhino Compute, but don’t need to be uninstalled.

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.

If you’re using Windows, make sure you install a 64-bit version of Python.

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

You need some simple Python code - only 3 lines - to run a Grasshopper file from the app.

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

If you're using VS Code, then you should end up with something like this

1

Create an empty folder

Call it something like GenerativeEngineering

2

Open the folder in your IDE

If you’re using an IDE (Integrated Development Environment) like VS Code, open your folder in it.

If you’re not using an IDE, skip this step.

3

Open a terminal at your folder

If you’re using an IDE, you can most easily do this there.

Make sure the terminal is open at the folder you’ve created. In the terminal prompt you can normally see the folder the terminal is running in.

4

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.generative.vision/simple generative-server-grasshopper-connector
python -m generative.server --version

If this is successful, the version of generative-server 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.

5

Create a folder within your repository

Make a folder, for example called functions, within your repository. This will hold your Python code.

6

Create a Python file within your folder

Create a file, for example called generative_functions.py within your folder to hold the Python code.

Create a Generative Function

Copy the below to the Python file created above, defining the location of the Grasshopper file relative to where your terminal is running (which should be the root of the repository).

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

class MyFirstGrasshopperFunction(GrasshopperFile):
    file_path = "functions/grasshopper-torus.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 a function server

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

The command assumes that your generative functions are in a folder within your repository called functions. If that’s not true, replace the word functions with the relative path to where your generative functions Python file is, or remove it entirely if your Python file is in the folder where your terminal is running.

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

When you make changes to your function, manually stop the server (Ctrl + C) 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 cause issues 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

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.