Integrating script files or script code into the procedure sequence

You can call a script file or script code at each point of the procedure sequence.

Note: Only actions that would disrupt current running procedures, for example, LoadVersion, are not permitted.

Note: You should carefully consider whether to integrate scripts directly or as a file. Scripts that you include as a file are executed in a separate thread. Scripts whose code you enter directly are executed in the main thread. This has the following advantage:

  • COM access is faster than when using a script file.

It also has disadvantages:

  • The program interface freezes and Windows reports after a few seconds that the program may have crashed.
  • You cannot open program windows via COM, as the program interface does not respond while the script is running.

1.  From the Calculate menu, choose Procedure sequence.

The Procedure sequence window opens.

2.  Click the Create button.

The Procedure window opens.

3.  Select Miscellaneous > Run script.

Note: You will find scripts integrated as add-ins in Visum in the AddIn folder (Embedding add-ins automatically via a project directory).

4.  Confirm with OK.

The Run script procedure is inserted into the procedure sequence.

Select script environment for Python

1.  In the Operations section, select Edit.

The Run script window opens.

2.  From the drop-down list Script environment, choose the desired entry for Python.

Element

Description

Python 3.13

  • Standard environment
  • All scripts run in the main thread (valid for script files and directly entered code)
  • Supports COM
  • COM scripts run faster because they are executed in the main thread
  • Not compatible with wxPython
  • No modules are already imported, so the required modules, for example "import visum" or "import numpy", must be imported with the script

Python 3.13 (PTV Hub cloud computing)

  • Recreates the cloud environment as precisely as possible in the desktop:
  • All scripts run in the main thread
  • Not compatible with wxPython
  • Does not support COM
  • Only 'numpy' as an external module, no other third-party modules
  • No own virtual environments

Python 3.13 (Legacy)

  • Behaves like Visum 2025
  • wx environment: specified script files run in a separate wx thread
  • Only environment with support for wxPython
  • Always used for:
  • All add-ins (including, for example, the parameter windows)
  • Python console in the Scripts > Python Console menu
  • Script files that are selected via the Scripts > Execute script file menu

You can use procedure steps with the three environments in one version file.

Integrate script file

Scripts that you include via a separate file are not executed in the main thread, but in a separate thread.

1.  In the row of the created procedure, click the button in the row Variant/File.

The Open script window opens.

2.  Select the desired script file.

Note: By default, you can use script files with the extensions *.vbs, *.js, *.pys or *.py. You can only use script files created with Ruby, Perl, or TCL script environments if the environments are registered in Windows.

3.  Click the Open button.

The script file is read from file and displayed in the Variant/file column (Setting the procedure sequence).

Integrate script code

1.  In the Operations section, select Edit.

The Run script window opens.

2.  From the drop-down list Script environment, choose the desired entry.

3.  Select the option Directly enter script code.

4.  Enter the desired script code in the input field.

Notes: In your script, you can access the ongoing Visum session via the global variant Visum. You can find more information under HelpCOM help.

5.  Confirm with OK.

The script code is integrated into the procedure sequence.

Tip: You can debug your Python scripts more easily if you save Visum messages from the script, which you can see in the Messages window.

  • ►  Enter print("Note") in your script if you want to log notes in the message file.
  • ►  Enter print("Warning", file=sys.stderr) in your script if you want to log warnings in the message file.