Skip to main content
Version: 14

viktor.external.dynamo

DynamoAnalysis

class viktor.external.dynamo.DynamoAnalysis(files=None, executable_key='dynamo', output_filenames=None)

Bases: GenericAnalysis

New in 14.17.0

DynamoAnalysis can be used to evaluate a matlab script on third-party infrastructure. The script is expected to be blocking, i.e. if the executable is invoked from command prompt, it should wait until the script is finished. For security purposes the executable that should be called has to be defined in the configuration file of the worker.

Usage:

files = [
    ('input1.txt', file1),
    ('input2.txt', file2)
]
analysis = DynamoAnalysis(files=files, output_filenames=["output.txt"])
analysis.execute(timeout=60)
output_file = analysis.get_output_file("output.txt")

Exceptions which can be raised during calculation:

Parameters:
  • files (Optional[List[Tuple[str, Union[BytesIO, File]]]]) – Files that are transferred to the working directory on the server. Each file is a tuple containing the content and the filename which is used to save on the infrastructure.

  • executable_key (str) – The key of the executable that needs to be evaluated. This key should be present in the configuration file of the worker, defaults to run_matlab.

  • output_filenames (List[str]) – A list of filenames (including extension) that are to be transferred back to the SDK. This filename is relative to the working directory.

At least one of the attributes above should be included in the call.

Raises:

ValueError – when no attribute is included in call.

DynamoFile

class viktor.external.dynamo.DynamoFile(file)

Dynamo file instantiated from an existing input .dyn file. This class allows for easy transformation of input nodes by means of the update() method.

Parameters:

file (File) – Dynamo input file (.dyn).

generate()

Generate the (updated) Dynamo input file.

Return type:

File

get_node_id(name)

Retrieve the unique node id by name.

Parameters:

name (str) – Name of the node.

Return type:

str

update(name, value)

Update the value of an input node with specified name.

Parameters:
  • name (str) – Name of the input node.

  • value (Any) – New input value.

Return type:

None

convert_geometry_to_glb

viktor.external.dynamo.convert_geometry_to_glb(file, filter=None)

Convert a Dynamo geometry file (.json) to a GLB file, which can directly be used in a GeometryResult.

Filter specific geometric objects by id, obtained by calling get_node_id():

input_file = DynamoFile(file)
sphere_id = input_file.get_node_id("Sphere")  # geometry node called "Sphere"
...
geometry_file = dynamo_analysis.get_output_file(filename='geometry.json', as_file=True)  # viktor.external.dynamo.DynamoAnalysis
glb_file = convert_geometry_to_glb(geometry_file, filter=[sphere_id])
Parameters:
  • file (File) – Dynamo geometry file (.json).

  • filter (List[str]) – Filter geometric objects by id (default: include all).

Return type:

File

get_dynamo_result

viktor.external.dynamo.get_dynamo_result(file, id_)

Extract results from a Dynamo output file (.xml) by means of a node ‘id’, which can be obtained by calling get_node_id().

Example using BytesIO:

input_file = DynamoFile(file)
output_id = input_file.get_node_id("Area")  # output node called "Area"
...
output_file = dynamo_analysis.get_output_file(filename='output.xml')  # viktor.external.dynamo.DynamoAnalysis
result = get_dynamo_result(output_file, id_=output_id)

Example using File:

input_file = DynamoFile(file)
output_id = input_file.get_node_id("Area")  # output node called "Area"
...
output_file = dynamo_analysis.get_output_file(filename='output.xml', as_file=True)  # viktor.external.dynamo.DynamoAnalysis
with output_file.open_binary() as f:
    result = get_dynamo_result(f, id_=output_id)
Parameters:
  • file (BinaryIO) – Dynamo output file (.xml).

  • id – Unique identifier of the output result node.

Return type:

str