Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Expand
titleHow 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'

Code Block
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.

Code Block
@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:



Info
titleNote

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!


...