Running a Python 3 script when an Exercise is loaded

Exercises can be customized by executing custom Python 3 scripts. This type of script is executed when an exercise is loaded by the Console. As a prerequisite, the Exercise must have a valid Scene associated to it for the script to be ran.

Adding an Exercise Script to an Exercise

To add a script to an Exercise, the Exercise Script extension must be added to an Exercise. This extension is available in the extension toolbox of the Exercise List document.

To add it to an Exercise, simply drag and drop the extension from the toolbox to the Explorer, under any Exercise extension.

To specify the Python 3 script file, navigate to the Property Browser to browse and assign a .py file to the Script File parameter of the newly added extension. Then, make sure to save the Exercise List document.

Note that many scripts can be added to an exercise.

Implementing the Python script

For an Exercise's script to be ran properly, some basic requirements must be met:

  • The Vortex module must be imported.
  • The following callback must be defined: on_exercise_loaded(scene, sequence)
    • The scene argument is the object representing the Scene that is loaded by the Exercise. It can be used to interact with various extensions contained within it and to set them up prior to the simulation.
    • The sequence argument is the full file path to the exercise sequence, if any is specified. It is empty if there is none.

In short, the Exercise Script should at least contain the following:

import Vortex

def on_exercise_loaded(scene, sequence):
    # Enter your code here