Creating and exporting FMU > FMU Export via scripting
Optional model preparation steps
To increase the automation level of an FMI export process, for example in the context/scenario of an “FMU batch-generator”, you can create the model through scripting, before exporting it as an FMU. You can apply some modifications to an existing model (with a previously-defined FMI interface block) before exporting it.
To create a model from scratch through scripting, consult the Simcenter Amesim API for the relevant Python API functions.
To modify a previously-created model using Python API functions, a convenient starting point can be to use the Generate model script command. Select File
Generate model script > Python. You can then adapt the resulting Python script before running the FMU export script.
A typical use case consists in defining relevant (non-null) default start values for the inputs of the FMU (see Open-loop simulations for basic model checks). For a model called MyModel.ame, the simple example below shows how to use the AMESetInterfaceVariableStartValue function to set the default start value of a future FMU input called rpm to 1450.6. More precisely, this rpm variable is a label of an output of an FMI interface block whose alias is amesim_interface.
Note
amesim_interface is the default value for interface block aliases.
You can then adapt this use-case to your specific requirements (model name, variable names, interface block aliases, default start values, and so on).
Figure 62: Interface block with one default start value to be defined
Copy# Import needed Python modules import os, sys if 'ame_apy' not in sys.modules: try: from ame_apy import * except ImportError: print('Unable to import Simcenter Amesim API module.\nCheck the AME environment variable.') # Get license and initialize Simcenter Amesim Python API AMEInitAPI() # Open the model AMEOpenAmeFile('MyModel.ame') # Set non-null default start values for one model input AMESetInterfaceVariableStartValue('rpm@amesim_interface', '1450.6') # Generate code AMEGenerateCode() # Save the model AMECloseCircuit(True) # Return license and close Simcenter Amesim Python API AMECloseAPI(False) |
Copy# Import needed Python modules import os, sys if 'ame_apy' not in sys.modules: try: from ame_apy import * except ImportError: print('Unable to import Simcenter Amesim API module.\nCheck the AME environment variable.') # Get license and initialize Simcenter Amesim Python API AMEInitAPI() # Open the model AMEOpenAmeFile('MyModel.ame') # Set non-null default start values for one model input AMESetInterfaceVariableStartValue('rpm@amesim_interface', '1450.6') # Generate code AMEGenerateCode() # Save the model AMECloseCircuit(True) # Return license and close Simcenter Amesim Python API AMECloseAPI(False) |
|---|---|
Copy# Import needed Python modules import os, sys if 'ame_apy' not in sys.modules: try: from ame_apy import * except ImportError: print('Unable to import Simcenter Amesim API module.\nCheck the AME environment variable.') # Get license and initialize Simcenter Amesim Python API AMEInitAPI() # Open the model AMEOpenAmeFile('MyModel.ame') # Set non-null default start values for one model input AMESetInterfaceVariableStartValue('rpm@amesim_interface', '1450.6') # Generate code AMEGenerateCode() # Save the model AMECloseCircuit(True) # Return license and close Simcenter Amesim Python API AMECloseAPI(False) |
If the above script is named Start_values.py, you call it using the Python distribution provided with Simcenter Amesim.
Note
The AME environment variable must be set to the Simcenter Amesim installation path.
Call the script as follows:
Windows:
%AME%\python.bat Start_values.pyLinux:
$AME/python.bat Start_values.py
Note
In addition to the AMESetInterfaceVariableStartValue function, you can also use a function called AMEGetInterfaceVariableStartValue to get the value of an already-defined start value. In the previous example, it would take rpm@amesim_interface (the label of interface block output @ alias of the interface block/instance) as its unique argument.
Source: https://docs.sw.siemens.com/en-US/doc/254352342/PL20250521841123434.amesim_collection.Functional_Mockup_Interface/xid2290029 · retrieved 2026-07-17