Overview

A file or function that takes inputs and returns outputs, and has been made executable by the Generative Engineering Platform is referred to as a Generative Function.

For example, a Grasshopper file that creates a tower might take height, depth, width, material, and wind load as inputs and return its maximum deflection, an estimated cost, and a 3D model. Turning this file into a Generative Function allows design space exploration and optimisation to be performed in the app, like minimising the deflection or finding tradeoffs between materials and cost.

This section explains how to use the Grasshopper connector to create a Generative Function from a Grasshopper file.

Grasshopper file requirements

To configure your Grasshopper file for use with Generative Functions, you need to define all inputs and outputs using specific node types.

If you’ve used the Hops plugin for Grasshopper then these nodes should already be familiar to you.

For an example, see the First Experiment guide.

Inputs

Navigate to the Params tab and open the Utils section.

For each input you want to expose in your Generative Function, use an appropriate node such as Get Number, Get Integer, or Get Point.

Connect each input node to a source node that provides a value, such as a Number Slider. These values will serve as:

  • Default values in the Generative Function
  • Evaluation parameters used during startup on the function server to determine output types

Ensure that each input node is given a unique, descriptive name by right-clicking the node and updating its label.

Outputs

Use Context Bake nodes to designate each output, such as geometry or numerical values.

Mesh geometry is required for visualisation - pure BRep geometry in 3DM format cannot be visualised in the app.

Outputs must be flattened to a single data tree branch. While Context Bake supports multiple branches, only the first branch is currently visible in the Generative app.

For lists within the first branch:

  • If the list contains geometry, it will be grouped into a single file for exporting, and will be displayed together in the app.
  • For non-geometry values, only the first list item will be displayed in the Generative app.

Future developments will improve this experience.

Context Print nodes can also be used for outputs, but are generally not recommended, as all contents are concatenated into a single string output.

Ensure that each output node is given a unique, descriptive name by right-clicking the node and updating its label.

Connecting a Grasshopper file to the app

Once you’re setup with Python, use your Python package manager to install Generative packages generative-core, generative-server and generative-server-grasshopper-connector from pypi.generative.vision. There are instructions for how to do this in a section of the First Experiment guide.

Python is required because it’s the way we currently deploy our connectors, but each Grasshopper file only requires 3 lines of code, simply to specify the location of the file.

Creating a Generative Function

To create a Generative Function from a Grasshopper file, define the location of the Grasshopper file, in a Python file in the folder or repository that has access to the Python packages, using the following syntax.

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

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

Additional variables

Some additional variables can be set to customise the Generative Function.

To use them, set the variables value in the class definition:

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

If your Grasshopper file can take a long time to compute, set a suitable time limit for each evaluation of the file by setting timeout_seconds. Defaults to 60 seconds.

server_url

If you’re running Rhino Compute on a different url to the default http://localhost:6500 (e.g. in a Virtual Machine), then also set the class variable server_url to its location:

Ensure a Rhino Compute server is running

We use Rhino Compute to communicate with Rhino.

A local Rhino Compute server can be started in multiple ways. The supported route is to use Rhino 8 or above, on Windows OS, with the Hops plugin installed. When those conditions are met, a Rhino Compute server is started in the background each time Grasshopper starts.

To see if a Rhino Compute server is running on the default URL, go to http://localhost:6500. You will see compute.rhino3d if the server is running.

Connect to the app

Once you have a Generative Function defined, you can connect this to the app.

See the connecting to app section for in depth guidance, but the following steps will normally be sufficient:

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.

By default, the app will reload every time the Grasshopper file is saved.