Skip to main content
Version: 14

viktor.external.grasshopper

GrasshopperAnalysis

class viktor.external.grasshopper.GrasshopperAnalysis(*, script, input_parameters=None)

Bases: ExternalProgram

New in v14.8.0

Perform an analysis using Grasshopper on a remote server by means of a worker. To start an analysis call the method execute(), with an appropriate timeout (in seconds).

To retrieve the output, call get_output().

Usage:

my_input_parameters = {
    'my_int': 1,
    'my_bool': True,
    'my_string': "test",
    'my_list': [1, 2, 3],
    'my_dict': {'{0;0;0}': [1], '{0;1;1}': [1, 2, 3]}
}
grasshopper_analysis = GrasshopperAnalysis(script=my_grasshopper_script, input_parameters=my_input_parameters)
grasshopper_analysis.execute(timeout=10)
output = grasshopper_analysis.get_output()

Exceptions which can be raised during calculation:

  • ExecutionError: generic error. Error message provides more information

Parameters:
  • script (File) – Grasshopper script (.gh)

  • input_parameters (Dict[str, Any]) – Input parameters to be passed to the grasshopper script in the form of a float dict. Key names will be matched with the Hops parameter names in Grasshopper and substituted accordingly

get_output()

Retrieve the output generated by running the Grasshopper analysis. Call method execute() first and get_output() afterward.

The output is in the form:

{
    "absolutetolerance": float,
    "angletolerance": float,
    "modelunits": str,
    "algo": str,
    "pointer": str,
    "cachesolve": bool,
    "recursionlevel": int,
    "values": list[dict]
    "warnings": list[str],
    "errors": list[str]
}
Return type:

dict