Vizard 8 » The Vizard IDE » Running scripts » Running scripts
8.1

Running scripts

Vizard scripts can be run using the run icon in the standard toolbar, selecting the Script > Run menu option, or by using the F5 keyboard shortcut.

 

The Script menu also contains the following run options:

For debugging purposes, a script can be run in debug mode. See the Vizard debugger section for more information.

Automatic save

All run options automatically save the script prior to running it. If there is no saved file associated with the script, a Save As dialog will be displayed.

 

By default, all open documents will be saved when running a script. This is useful when your program is split up into multiple modules and you want to ensure you are running with the latest changes. This behavior can be disabled using the Save all documents when running script setting in the Options window.

Script already running

If you attempt to run a script that is already running, a dialog with Relaunch, Focus, and New Instance options will be displayed:

Relaunch is useful for running a script that's been modified while the graphics window was open or to start the script from the beginning. If you forgot the script is running minimized or behind other windows, you can use the Focus option to bring it to the foreground. New Instance will run the script and keep the existing script running as well.

Run Arguments toolbar

The Run Arguments toolbar allows specifying an arbitrary string that will be passed as optional arguments to the script when it is run. Passing arguments allows you to change the behavior without modifying the script. For example, if your script logs certain data to a file, you can pass the name of the log file as an argument:

Note: Run arguments are separated by spaces. If an argument value contains a space then you need to place double quotation marks around the argument when constructing your string.

To access the run arguments within your Vizard script, use the Python sys.argv list. The first value of the list is the name of the script that is running. The remaining elements of the list are all the arguments passed to your script. Continuing with the above example, you would use the following code to access the name of the log file argument:

import sys
LOG_FILE = sys.argv[1]

You can pass any number of arguments to your script, and they will be appended to the sys.argv list. The following code shows how to iterate and print all the available arguments:

import sys
for arg in sys.argv[1:]:
    viz.logNotice(arg)