Skip to main content

Dynamo Sandbox

New in v12.12.0

This guide is only relevant for Dynamo Sandbox, not to be confused with the Dynamo plugin for Revit!

A dynamo module has been developed by VIKTOR which can be used for easy updating of Dynamo input files and processing output files (results + geometry). With the Generic worker, you will also be able to completely automate an integration with Dynamo Sandbox.

Updating a model

An existing Dynamo model can be passed to VIKTOR's DynamoFile as shown below. With the update method, the value of input nodes can be updated. When all inputs have been updated as desired, the generate method can be used to generate an updated File object.

from viktor import Filefrom viktor.external.dynamo import DynamoFilefile = File.from_path(Path(__file__).parent / "template.dyn")dyn_file = DynamoFile(file)# update input nodesradius = params.radiusdyn_file.update('Radius', radius)  # input node called "Radius"...# generate updated fileinput_file = dyn_file.generate()

Running an analysis

Integrating with Dynamo Sandbox can be done using the GenericAnalysis class (worker required):

from io import BytesIOfrom viktor.external.generic import GenericAnalysisfiles = [    ('input.dyn', BytesIO(input_file.getvalue_binary())),]# run the analysisgeneric_analysis = GenericAnalysis(files=files, executable_key="dynamo", output_filenames=["output.xml", "geometry.json"])generic_analysis.execute(timeout=60)

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

The executable_key in the example above refers to the "dynamo" command. This command should also be specified in the configuration file on the server, located in the same directory as the worker. By pointing to the file location of DynamoWPFCLI.exe (Dynamo Sandbox command-line interface), the Dynamo Sandbox integration can be established. With additional arguments we can specify where the input model is located and where the results should be exported to.

See the Dynamo Sandbox documentation for more info on running Dynamo from the command-line.


path: 'C:\path\to\DynamoSandbox\DynamoWPFCLI.exe'
- '-o'
- 'input.dyn'
- '-v'
- 'output.xml'
maxParallelProcesses: 1

Geometry can also be exported, for which an installation of either "FormIt" or "Revit" is required:

- '-gp'
- 'C:\Program Files\Autodesk\FormIt' # or Revit
- '-g'
- 'geometry.json'

Processing results

After running the analysis, the output file (.xml) can be obtained using:

output_file = generic_analysis.get_output_file("output.xml", as_file=True)

With the as_file flag, VIKTOR is instructed to return a File object which can directly be passed to the get_dynamo_result function. The results can then be obtained by node id, which corresponds to the same node id as the input file.

from viktor.external.dynamo import DynamoFile, get_dynamo_resultdyn_file = DynamoFile(file)...output_id = dyn_file.get_node_id("Area")  # output node called "Area"with output_file.open_binary() as f:    result = get_dynamo_result(f, id_=output_id)

Results will be returned as str type, which means you will need to take care of conversions in the app.

Processing geometry

In a similar matter the geometry file can be obtained after the analysis has been performed. With the helper function convert_geometry_to_glb, you can convert it to a GLB type file, which can directly be visualized in a GeometryResult.

from viktor.external.dynamo import convert_geometry_to_glbfrom viktor.views import GeometryView, GeometryResult@GeometryView(...)def geometry_view(self, params, **kwargs):    ...    geometry_file = generic_analysis.get_output_file('geometry.json', as_file=True)    glb_file = convert_geometry_to_glb(geometry_file)    return GeometryResult(glb_file)