Chapter 19. Scripting

Table of Contents

19.1. Scripting
19.1.1. Scripting Context Menu
19.2. Scripting Assistant

Scripting is used to implement the dynamic functionality of module user interfaces and applications (which are defined as macro modules) in MeVisLab.

Scripting is done in the context of a module. Via the script context variable of the module (ctx), access is given to the module instance itself as well as to all members of the module like fields, input/outputs, and GUI controls. This way, getting/setting field values (module parameters), connecting/disconnecting fields, implementing dynamic user interfaces, and much more can be done dynamically .

In the context of an MLABMacroModule, access to the contexts of all modules contained in the modules macro network is available (recursive descend).

For scripting in MeVisLab, two script languages are supported:

Both script languages have the same “view” on the MeVisLab API as both use the Qt Meta Object System to find out about the MLAB object features.

For the doxygen documentation of the scripting interface, see the MeVisLab Scripting Reference.

[Tip]Tip

It is possible (but not recommended) to include single line script statements in MDL script files.

19.1. Scripting

Figure 19.1. Scripting Editor

Scripting Editor

The Scripting View works like the Scripting console that can be opened via the menu bar, ScriptingShow Scripting Console.

Example listing in Python (the code has to be entered one line at a time, and without any indents):

# get module context 
module = ctx.module("LocalImage") 

# set/get module field value 
filename = module.field("trueName").value
module.field("name").value = "$(DemoDataPath)/bone.tiff"

# connect fields 
ctx.connectField("View2D.inImage","LocalImage.outImage")

# open GUI window control 
window = ctx.module("View2D").createWindow("Viewer")
window.setTitle("HelloWorld")
ctx.module("View2D").showWindow("Viewer")

Figure 19.2. Scripting Example

Scripting Example

19.1.1. Scripting Context Menu

The context menu of the Scripting View contains the usual commands for text editing, see also Section 4.2, “Edit Menu”.

Figure 19.3. Scripting Context Menu

Scripting Context Menu

In addition, three options are available:

Show MeVisLab Scripting Help

Opens the Scripting Reference documentation (HTML) in the default web browser.

Scripting Language

Can be switched from the default (as defined in the Preferences) to the other script language.

Clear

Clears the scripting console.