Skip to main content

Rhino / Grasshopper

Rhino can be executed through command-line instructions, which also allows to execute a grasshopper script. See the Rhino documentation for more info on running Rhino from the command-line interface.

VIKTOR's Rhino / Grasshopper integration requires a Generic worker.

from viktor.external.generic import GenericAnalysis# Generate the input file(s)files = [    ('input.json', BytesIO(b'filecontent1')),]# Run the analysis and obtain the output filegeneric_analysis = GenericAnalysis(files=files, executable_key="run_grasshopper", output_filenames=["output.json"])generic_analysis.execute(timeout=60)output_file = generic_analysis.get_output_file("output.json")

GenericAnalysis.execute needs to be mocked within the context of (automated) testing.

The executable_key in the example above refers to the "run_grasshopper" command. This command should also be specified in the configuration file on the server, located in the same directory as the worker:


path: 'C:\scripts\run_grasshopper.bat'
workingDirectoryPath: 'C:\scripts'
maxParallelProcesses: 1 # must be one, please do not change

In this example, the worker will run "run_grasshopper.bat" when a job is received. This batch script can be used to for example call Grasshopper which uses the input.json file that has been sent along with the job in GenericAnalysis above:


SET rhinoFilePath=""C:\scripts\analysis.3dm""
SET ghFilePath=""C:\scripts\""

"C:\Program Files\Rhino 6\System\Rhino.exe" /nosplash /runscript="-open %rhinoFilePath% -grasshopper document open %ghFilePath% _save _enter exit _enter"