Dassault Systèmes Python API Scripts

The Python Script adapter lets you run Python scripts and logging APIs and to perform scalar parameter and general mathematical operations.

All the APIs are present within SimProcess.py (main module) and the same module re-exposes these APIs. To access all the supported APIs, you can import the SimProcess.py module.

This page discusses:

def getInputParameters() -> Dict[str, Any]

This function retrieves the input parameters required for execution from the activity parameters (excluding object parameters). Array parameter values are returned as lists, and multidimensional array values are returned as nested lists.

Returns
dict: A dictionary containing input parameters with their names as keys. The parameter name is the key.
Raises
  • ValueError: If the parameter name is not found in the activity parameters.
  • RuntimeError: If no input parameters are found.
Syntax

input_params = SimProcess.getInputParameters()

  • Input_params: Dictionary of input parameters.
  • SimProcess: API entry module.

Example
import SimProcess as sp

input_params = sp.getInputParameters()
out1 = input_params['in1'] + input_params['in2']
out2 = input_params['in3'] - input_params['in4']
import SimProcess as sp

input_params = sp.getInputParameters()
print(input_params)
# Output: {'in1': 0.5, 'in2': 0.5, 'A': [[1, 2, 3], [4, 5, 6]] 'B': [[7, 8, 9], [10, 11, 12]]
In the example above, in1, in2, in3, and in4 are input activity parameters. With the parameter name as the key, the adapter is fetching the input parameter values and doing arithmetic operations.
The API supports InOut parameter similar to In parameters.

def setOutputParameters(parameters_dict: dict[str, typing.Any]) -> None

This function sets the output and InOut parameter values in the execution parameters (excluding object parameters). For array parameter values, the function expects lists or nested lists based on dimensions. It sets the current parameter's value.

Parameters
parameters_dict (dict[str, Any]): A dictionary containing parameter names as keys and values as values. The keys represent parameter names (strings), and the values represent the corresponding values of any type.
Raises
  • ValueError: If the parameter name is not found in the activity parameters.
  • RuntimeError: If no output parameters are found.
  • Returns: None
Syntax
setOutputParameters(parameters_dict: dict[str, typing.Any])

Example
import SimProcess as sp

input_params = sp.getInputParameters()
out1 = input_params['in1'] + input_params['in2']
out2 = input_params['in3'] - input_params['in4']
sp.setOutputParameters({'out1': out1, 'out2': out2})
import SimProcess as sp


def array_parameter_addition():
    """
    Performs matrix addition using input parameters A and B fetched from `sp.getInputParameters()`.
    Updates the output parameter `{'C': result}` using `sp.setOutputParameters()`.
    Example:
    matrix1 = [[1, 2, 3], [4, 5, 6]]
    matrix2 = [[7, 8, 9], [10, 11, 12]]
    result=[[8, 10, 12], [14, 16, 18]]
    """
    input_params = sp.getInputParameters()
    matrix1 = input_params['A']
    matrix2 = input_params['B']
    if len(matrix1) != len(matrix2) or len(matrix1[0]) != len(matrix2[0]):
        raise ValueError("Matrices must have equal dimensions for addition.")

    result = [[matrix1[i][j] + matrix2[i][j] for j in range(len(matrix1[0]))] for i in range(len(matrix1))]
    sp.setOutputParameters({'C': result})


array_parameter_addition()
In the example above, out1 and out2 are output parameters and through the setOutputParameters API you can set output parameters.
Note: This API supports both Out and InOut parameters.

def logInfo(message:str) -> None

The API provides information logs of a job at run time.

Parameters
  • Input: String message
  • Returns: None

Example
import SimProcess as sp

input_params = sp.getInputParameters()
out1 = input_params['in1'] - input_params['in2']
sp.logInfo("The difference between two input parameters was "+str(out1))
sp.setOutputParameters({'out1': out1})
The information log message at job log. By default the message is an empty string.

def logDebug(message:str) -> None

The API provides debug logs of a job at runtime. By default, the message is an empty string.

Parameters
  • Input: String message
  • Returns: None

Example
import SimProcess as sp

sp.logDebug("Python Script  Execution Started")
input_params = sp.getInputParameters()
out1 = input_params['in1'] - input_params['in2']
sp.setOutputParameters({'out1': out1})
sp.logDebug("Python Script Execution was Ended")

def logWarn(message:str) -> None

The API provides warning logs of a job at run time. By default, the message is an empty string.

Parameters
  • Input: String message
  • Returns: None

Example
import SimProcess as sp

input_params = sp.getInputParameters()
out1 = input_params['in1'] - input_params['in2']
if out1 == 0:
    sp.logWarn("The difference was zero")
sp.setOutputParameters({'out1': out1})

def logError(Message: str, Reason: str, Advise: str, Explanation: str) -> None

The API provides error logs of a job log at run time. By default, all the arguments are empty strings.

Parameters
  • Input: String message
  • Returns: None

Example
import SimProcess as sp

input_params = sp.getInputParameters()
sp.logInfo('The Input Parameters are ' + str(input_params))
out = input_params['in1'] - input_params['in2']
if out > 0:
    sp.logInfo('The Output was ' + str(out))
elif out == 0:
    sp.logWarn('The Output was Zero')
else:
    sp.logError('The Output was less than zero', 'Input2 is greater than Input1', 'Modify the Inputs according '
                                                                                  'to Mathematical Operation',
                'Subtracting greater number from smaller number yields negative result')
sp.setOutputParameters({'out': out})