Automating Post-Processing in Dymola Using Commands

After running a simulation in Dymola, engineers often need to perform several post-processing tasks, such as generating plots, analysing results, or executing custom scripts. These tasks can be automated using Commands, which are stored within the experiment setup. This blog explores how to create and use Commands in Dymola to streamline your simulation workflow.

Creating a Plot Command in Dymola

Let’s start by extending the Suspensions.Experiments.OpenLoop.Acceleration experiment to create a test setup, as shown in Figure 1.

Figure 1. Package for testing vehicles accelerating

Once this experiment is simulation, a customised plot should automatically appear, like the one in Figure 2.

Figure 2. Vehicle driver signals, velocity and acceleration for an accelerating car.


Next a command to reproduce this plot is added as in Figure 3.

To automate this plot generation:
1. Create the plots
2. Go to Simulation > Commands > Add Commands
3. Select Plot window setup
4. Select No pre-condition
5. Check “Automatically run after simulation”

The plot has been customised by right clicking on the plot and selecting Setup.

Figure 3. Adding plots as a Command to run automatically after simulation


Understanding the Command Setup

From the Command section (see Figure 1), you can choose whether the Command is a:

*Script
*Function
*List of functions


These are stored in the ‘__Dymola_Commands’ annotation of the experiment. An exception is the Use
Modelica standard plot setup
,which stores figures in the Documentation annotation instead.

Key Options Explained:

1. Use Modelica standard plot setup: Saves figures in a simpler format with
limited functionality.

2. Before execution model must be: Ensures the model is translated or simulated
before the Command runs.

3. Execute when checking package: Useful for pre-processing when using Graphics >
Check > With Simulation.

4. Prompt for arguments: Allows user input during execution.

5. Inherit command: Enables reuse of Commands across experiments.


⚠️ Note: If Plot window setup is selected, Inherit command is disabled. To enable inheritance, manually edit the
Dymola_Commands annotation by adding inherit=true.

Figure 4. Modifying the “Plots” Command to make it inheritable, by adding inherit=true

Using Experiment Names in Inheritable Commands

The Claytex.Functions.RealTime.run() function can be used to simulate with real-time settings. This function can be run with Claytex.Functions.RealTime.run(<experiment name>) where experiment name is the Package Browser path to the experiment.

To make an inheritable Command to execute run() on the experiment that is selected in the Package browser the ModelManagement.Structure.AST.Misc.ClassShownInBrowser() can be used as the experiment name. An example of creating such a Command is below:

🎥 Video: Animation showing how to create an inheritable Command that uses an experiment name as an input

Creating a Script to Avoid Overwriting Figures

In Figure 2 the Command uses id=2, so it will overwrite an existing figure if it has id=2. To avoid this, use a script that dynamically assigns a new figure ID.

Figure 5. Script to generate a figure with subplots in a new figure.

Steps:
1. Copy the createPlot() functions into a text editor.
2. Change the first id to -1 to create a new figure.
3. Assign the returned figureId to subsequent plots.
4. Save the script in the Resources folder for relative referencing.

Conclusion

Using Commands in Dymola allows you to automate post-processing tasks like plotting, scripting, and simulation setup. Whether you’re working with real-time simulations or customizing plot behavior, Commands can significantly enhance your productivity and consistency across experiments.

Written by: Garron Fish – Chief Engineer

Please get in touch if you have any questions or have got a topic in mind that you would like us to write about. You can submit your questions / topics viaTech Blog Questions / Topic Suggestion

CONTACT US

Got a question? Just fill in this form and send it to us and we'll get back to you shortly.

Sending

© Copyright 2010-2025 Claytex Services Ltd All Rights Reserved

Log in with your credentials

Forgot your details?