Documentation Home Page RT-LAB Home Page
Pour la documentation en FRANÇAIS, utilisez l'outil de traduction de votre navigateur Chrome, Edge ou Safari. Voir un exemple.

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

This chapter describes how to use Python script and the macro recorder.

Macro Recorder Overview


The macro recorder is a utility that automates repetitive and tedious tasks done on the real-time simulator. It records all actions performed with RT-LAB and saves them as a set of API commands in the Python native language (see the Python API Reference Guide for more details on the RT-LAB API).

The output of the macro recorder is a Python script module. Once the macro is recorded, RT-LAB lets you modify and edit the macro (script) using a rich editor and then easily play it back to perform simple or complex sets of tests without needing programming skills.

The macro recorder is often used while changing model parameters and interacting with the behavior of the simulation.

The recorded macro can be used to create sequences of maneuvers to control the simulator and model. It is also possible to manage the simulator’s execution mode and configure all simulator parameters and settings.

Before you start to record a new macro, plan the actions you want to perform on the project and simulator. Errors and corrections are also recorded. RT-LAB stores the result in a Python script function.

Recording a New Macro

To record a new macro:
Select the project from the Project Explorer view; only actions performed on this project will be recorded.

On the Tools > Python menu, click Record item, or simply click the Record item in the drop-down menu of the Python toolbar button.

The New Macro dialog box will appear:

In the New Macro dialog, type the script’s file name where it will be stored. By default, the script will be located in the project’s scripts folder, but it is also possible to specify a different location such as a project’s folder or anywhere on file system.

  • Check/uncheck the Write time setting to record the time elapsed between actions in the macro.

When checked, the macro recorder will add a sleep command between all actions to simulate the time elapsed when recording.

  • Type the description for your macro.
  • Click Finish to start recording.
  • Perform actions on your project, such as changing parameters or configurations. These actions will be recorded.
  • On the Macro Recorder toolbar, click the pause and resume buttons to activate and deactivate recording project actions.

To stop recording, click one of the following items:

Stop recording button

from Macro Recorder toolbar

Stop recording menu item

in the Tools > Python menu

 Stop recording menu itemin the Python drop down menu in the main toolbar

RT-LAB will automatically open the Python editor for the newly recorded macro.

To cancel the recording, click the Cancel recording item in the Macro recorder toolbar.


Opening a Macro/Script


Follow these steps to open an existing macro/script:

  • Click Open file from the file menu and locate your file by browsing your disk or
  • Double click the Python script macro in the Project Explorer.
  • Make sure that your projet’s file system is visible by clicking the Filter resources button in the Project Explorer view.
  • Expand your project in the Project Explorer view and locate the Python script in the file system.
  • Double click the Python script macro.
  • Drag and drop a Python script macro from the Windows Explorer to the RT-LAB editor area.

Editing a Macro/Script

The macro/script editor has a rich set of functionalities that let you edit your macro/script easily. Here
is a brief description of the available features:

Syntax highlightingProvide different colors and text styles to be given to dozens of different
lexical sub-elements of the Python syntax. These include keywords, comments, control-flow
statements, variables, and other elements. Programmers often heavily customize their settings in
an attempt to show as much useful information as possible without making the code difficult to
read.
Code analysisProvides error finding in python programs. It finds common errors such as
undefined tokens, duplicated signatures and warns about things such as unused variables or
unused imports.
Code completionprovides context-sensitive completions and is enabled with Ctrl+Space key in
the editor.
RefactoringProvides functionalities to change the source code to improve code readability, reduce
complexity and improve the maintainability of the source code such as renaming, extracting,
inlining code elements.
Navigation ViewsOutline View, Hierarchy View, ...
Content AssistantsHelps user to write code faster and more efficiently by providing list of
accessible keywords such as variable, method, import, module, ...

Once your script is open in the editor, perform the following steps to edit your script:

  • Locate the part of your script you want to edit.
  • Type your text.
  • Save your file by clicking the Save button in the main toolbar.

Running a Macro/Script

Follow these steps to run a macro:

  • Select the Python script from the Project Explorer or click inside your script in the editor area.
  • On the Tools > Python menu, click Run item (Ctrl-F11), or simply click the Run item in the drop-down menu of the Python toolbar.

Debugging a Macro/Script

Follow these steps to debug a macro:

Open the Python script macro. See Opening a Macro/Script for more information.

  • Add breakpoint to your script:
  • Double-click the script’s left ruler or
  • Type Ctrl+F10 to open the context menu. If everything goes ok, you'll have the breakpoint shown in your sidebar (as below).

Right-click the file and choose to debug the file as a python run.



Note: if you want to re-run the last executed file, you can click F11 to debug it.



When it hits the break-point, it will ask you to go to the debug perspective (click YES to this dialog).

This perspective has the actions needed for debugging and allows you to see the variables and evaluate expressions.

Stack viewYou can see the variables in previous stacks by clicking on the stack to view.
Variables viewAllows you to see the globals and locals for the selected stack.
Breakpoints viewAllows you to see the breakpoints available and enable/disable any breakpoint.
EditorShows the code and highlights the line to be executed.
ConsoleShows the output of the Python script macro.

The basic things you can do in the debugger have some keybindings:

Step inF5
Step overF6
Step outF7
ResumeF8
  • No labels