Python Simulation Script

What is the Python Simulation Script

The Python simulation script item (PythonSimScriptItem) is an item corresponding to a Python script that is executed in conjunction with simulations. Scripts can be executed at timings such as the start and end of a simulation. For example, it can be used for purposes such as setting the state of the environment when a simulation starts, or processing the results when a simulation ends.

This function is provided by the PythonSimScript plugin.

How to Use

A script file is loaded from the main menu with “File” - “Load” - “Python Script for Simulation”.

Place the loaded item under the world item of the target simulation and turn on its check. Then, when a simulation is executed in that world, the script is executed at the timing specified by the “Timing” property.

The execution timing of the script is determined relative to the initialization and finalization of the simulation, and can be selected from the following.

  • Before init. … The script is executed before the initialization of the simulation.

  • During init. … The script is executed during the initialization process of the simulation.

  • After init. … The script is executed after the initialization of the simulation is completed (when the simulation starts).

  • During final. … The script is executed during the finalization process of the simulation.

  • After final. … The script is executed after the finalization process of the simulation is completed.

Furthermore, by setting the “Delay” property, the execution of the script can be delayed from the above timing by the specified time.

Item Properties

In the Python simulation script item, the following properties are available in addition to the background execution and individual namespace properties, which are the same as those of the Python script item.

Property

Default value

Meaning

Timing

After init.

Selects the timing of executing the script from “Before init.”, “During init.”, “After init.”, “During final.”, and “After final.”.

Delay

0.0

The delay time from the above timing [s].

Simulation only

true

When true, the script is executed only at the timing linked with simulations. When set to false, manual execution with “Execute” in the context menu also becomes possible.