Scripting

The Scripting plugin provides functionality to automate certain steps in Via. This could be loading data, creating layers, setting layer options, changing views etc. In addition, the plugin provides an editor to edit and run scripts.

Table of contents

  1. Script Editor
  2. Example Script
  3. Automating Via

Script Editor

The Script Editor can be opened using the entry in the Tools menu. A window similar to the one shown below is opened. It provides a list of scripts on the left side (by default there is only one), and the actual editor area on the left side.

To add more scripts, the ”Plus”-Button can be pressed. Scripts can be renamed by double clicking on the script name in the list on the left side, or can be deleted by clicking on the close-symbol (x) next to the script name.

Example Script

Instead of lengthy API documentation, Via provides short examples and code snippets that show you how to automate certain tasks in Via. To access the examples, press the Show Examples button in the upper right corner of the Script Editor window. A floating palette will appear, providing examples on a variety of topics.

The following is an example script, loading some files, creating layers and saving a few screenshots at different times of day:

networkData=via.createDataset("sampleData/network.xml");
eventsData=via.createDataset("sampleData/10.events.xml.gz");

network=via.createLayer("network",networkData);
vehicles=via.createLayer("vehicles",networkData,eventsData);
activities=via.createLayer("activities",networkData,eventsData);

vehicles.loadEvents(); // this also loads the events for activities
via.sleep(1000); // give via a short amount of time to set up initial view
via.time="08:00:00";
via.view.zoomTo(100,100,4800,4300);

via.saveScreenshot("eight_oclock.png"); 16
for(i=0;i<10;i++){
  via.time = 7*3600 + i * 60*5; // proceed in 5min steps
  via.saveScreenshot("example_" + i + ".png");
}

Automating Via

Using scripts, Via can be integrated into automatic post-processing work-flows. Instead of writing and storing the scripts within Via, scripts can also be written in external text files. If Via is started with such a script passed as an argument, Via will automatically execute the script.

To start Via and automatically execute a script on Windows, just run the following command in your shell or command prompt:

Via64.exe myscript.via.js

On macOS, use the following:

open −a /Applications/Via/Via.app myscript.via.js

Please adapt the path to your Via installation accordingly.

Make sure your script file has the file-ending .via.js, so Via recognizes it properly. Also, don’t forget to include a call to via.quit() at the end of your script, otherwise Via will continue running and require resources on your system.