Scripting

The server portion of Vehicle Spy X is provided as a Python module that can be used to script every aspect of the application.

Setting up your Python environment

Visual Studio Code is the recommended development environment for Vehicle Spy X. In addition, Microsoft’s Python extension makes Python development a breeze.

To install the Python module, download the relevant .whl. file for your platform/Python version. Then, install the wheel using pip.

python3 -m pip install VSPYX_FILENAME_GOES_HERE.whl

Getting Started

To do anything meaningful with scripting you will need an instance of vspyx.Core.Application. By convention, an instance of this variable is usually named app.

import vspyx

app = vspyx.Core.Application.New()
app.Initialize(loadAllModules=False)

When a script is running inside of Vehicle Spy X (for example, in the Text API console), a global variable app will already be defined. A good habit is to check for this condition, so your script can both inside Vehicle Spy X and externally using the Python library.

import vspyx

if 'app' not in globals():
      global app
      app = vspyx.Core.Application.New()
      app.Initialize(loadAllModules=False)

Most functionality in Vehicle Spy X is contained in discrete modules. The loadAllModules argument to vspyx.Core.Application.Initialize() controls whether to load every available module. When loadAllModules is false each module can be explicitly loaded through vspyx.Core.ModuleManager.GetModule().

Note

When explicitly loading a module, any dependent modules will be automatically loaded.

vspyx.VehicleSpy.Module is a “glue” module ties together most other modules. It provides the functionality present in the traditional Vehicle Spy X UI experience.

vehicle_spy = app.ModuleManager.GetModule("VehicleSpy")
runtime = vehicle_spy.PrepareForStart()
vehicle_spy.Start()

# the instance is also cached as a property of app
app.VehicleSpy.Stop()

Tutorials