Integrate a Matlab or a Python function
When operations require calculation, we use Matlab/Simulink® blocks, or Python codes, that we integrate as operations in our UML description, as it is more performant than UML.
To integrate an external function, you first have to generate (or write) a xml file to ease the integration in the UML model.
The integration of external functions is only possible for the version pro of Designer.
INTEGRATE A PYTHON FUNCTION
From a python file containing useful functions, it is possible.
Python function integration requires Python 3.7, which was installed when the libraries were installed with Cygwin. If you forgot this step: (go to the page Cygwin installation)
Generate the integration file
The file automotive.py
contains the following python function:
def compute_braking_distance(speed, adhesionCoeff):
gravitationConst = 9.81
squareSpeed = speed**2
result = squareSpeed / (2*gravitationConst*adhesionCoeff)
return result
You can analyze this file to extract relevant informations to integrate this function in a model by using dedicated command.

This opens a dialog which enables to analyse the python file.

- Select the file to analyse
- Tick default to generate a file with the same name than your input file
- Click on Analyse Entry File
This will offer you the possibility to describe with more details the function and its parameters.

- Tick Generated case for each function you would use in the model.
- Click Update to complete the data about this function.
- Fill the data for each parameter and the function. This will help to integrate in the model.

- Validate the changes
- Click on Generate XML File to obtain the integration file
Integrate a Python function in the model
- Right click on an activity in a sequence diagram

- Select Edit > Complete Activity
- Chose Python function
- Click on Next

- Select the wanted python function. You can check the details and the parameters of the function
- Click on Next

- Update the mapping between inputs and outputs by chosing the variables of the model which have to be related to the variables of the function to call.
- Then, click on Finish

These steps will generate the code to use the Python function at runtime.
Additional build settings to use Python functions
With Cygwin (on Windows)
You need to use the Python libraries deployed via Cygwin for your code to compile correctly.
Right-click on the folder of the generated C++ project in the Project Explorer, then select "Properties".
The folder name is <Name_of_Model>_DefaultNode_<Name_Of_Variant>.
- Navigate to
C++ Build > Settings
, then in theTool Settings
tab, selectCygwin C++ Compiler > Includes
(refer to the screenshot below), - Add the path to your local Python includes in
Include paths (-I)
:C:\cygwin64\usr\include\python3.7m
(adapt based on your Cygwin installation), - Add
Python.h
toInclude files (-include)
,

- Go to
Cygwin C++ Linker
, - Add
python3.7
to Libraries.
