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

TestView Command | General | Macro

Macro Dialog Box


This command calls a Macro during the execution of the TestView script. It can be used to call Python, C-shell or Shell scripts.

It makes a local copy of the selected file at the following path:

[root project directory]/bank/mk/[name of file]

and creates an XML file to keep track of the source folder to the destination folder (one XML per macro).

It cannot send back information to the test sequence directly (e.g. it cannot use MATLAB's processing power). It nevertheless has quite a few uses, such as:

  • Pre-processing (e.g. to set up the I/O files)
  • Post-processing (e.g. to do data crunching using MATLAB)
  • Sending commands to external hardware (e.g. to reset protections between tests)

  • Modifying input data for the next test sequence in a batch list (e.g. using TestView's Excel interface)

Blocking call: It is sometimes necessary to wait for a macro to end before continuing with the test sequence, especially when interacting with external hardware. Also, when a macro calls a batch file that opens a program and 'blocking call' is enabled, the test sequence pauses until that program is closed.


 How Can I Send Parameters to a Python Script Using a Macro?

Using the Macro command, users may not send parameters to a Python script directly. However, they can use a batch file to forward the arguments to the Python script.

Example:

Create the following Python script and name the file 'dummy_python.py'

import sys

print 'Number of arguments:', len(sys.argv), 'arguments.'
print 'Argument List:', str(sys.argv)

Afterward, create a batch file that calls the python script. Name the file 'test_python.bat'. Tip: To create a batch file, create a .txt file and manually change the file extension to .bat.

Change the path on the second line to match the path where your 'dummy_python.py' file is located.

@echo off
python C:\OPAL-RT\Example\dummy_python.py %1 

Finally, in TestView add the Macro command and point to the batch file.

This will give:

Note

In the example above, the argument is the literal string 'a'.

If 'a' is a variable, then you need to write:

Where a = 1 in this example. It will give:


Do not forget to use the 'Assign' command to initialize the variable before using the 'Macro' command!



OPAL-RT TECHNOLOGIES, Inc. | 1751, rue Richardson, bureau 1060 | Montréal, Québec Canada H3K 1G6 | opal-rt.com | +1 514-935-2323