Launching scripts from the command line

This article describes how to launch Vizard scripts using the command line. Running scripts from the command line allows you automate the execution of your scripts using 3rd party apps. Using the command line also enables you to pass arguments to your script, allowing you to change the behavior without modifying the script.

Basic usage

The executable that runs Vizard scripts is winviz.exe and it is located in the bin directory of your Vizard installation folder (i.e "C:\Program Files\WorldViz\Vizard4\"). In general you will need to specify the full path to the executable when launching it. You can specify just the executable name if you run it from within the Vizard bin directory, but it is recommended to use the full path name.

To launch a script, you must pass the full path of the script as the first argument to winviz.exe. Here is a basic example that will launch the script demo.py:

"C:\Program Files\WorldViz\Vizard4\bin\winviz.exe" "C:\demo.py"

NOTE: Make sure to place double quotation marks around path names. They are necessary if the path contains any spaces.

Passing arguments

You can optionally pass arguments to your script when launching from the command line. For example, if your script logs certain data to a file, you can pass the name of the log file as an argument:

  • Vizard 3: The first argument after the script path is reserved for use by Vizard. All other arguments after this will be passed to your script. You can simply pass the value 0 as the reserved Vizard argument:

    "C:\Program Files\WorldViz\Vizard30\bin\winviz.exe" "C:\demo.py" 0 log1.txt
  • Vizard 4 and above: All arguments will be passed to your script:

    "C:\Program Files\WorldViz\Vizard4\bin\winviz.exe" "C:\demo.py" log1.txt

NOTE: Command line 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 command line.

To access the command line 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:]:
print arg