4.8. User Scripts

A user script is either a single .py Python file or an MDL .script file (with a .py and .mlab file, like any local MacroModule).

When a user script is started, MeVisLab creates a local macro module from the script and calls the run() function, which needs to be declared in the Python script. The run function takes a single argument, which is the context (macro module) that surrounds the currently active MeVisLab network.

Using this argument, the script can work on the active network, get the selected modules, etc.

For instance, the following script just prints the selected modules to the console:

  def run(macro): 
    print macro.network().selectedModules()
    

A user script can even show MDL windows from the run() method, which are declared in the .script file of the user script. The user script is destroyed after the last window it creates is closed.

User scripts are added to the Scripting menu by defining Action and SubMenu entries in a UserIDEMenus section in a user script's definition file. The user script's definition file can have any name, but it must have the extension def and it needs to be placed below the Modules directory of any package, because MeVisLab scans only the Modules directories recursively for the *.def files. It is preferred to place the user scripts into a folder named UserScripts below the Modules directory of your package.

Please have a look at the user script definition file MeVisLab/IDE/Modules/IDE/UserScripts.def and the example user scripts in MeVisLab/IDE/Modules/IDE/UserScripts/.

4.8.1. Example Scripts

  • Replace Inventor Group

    Replaces a single selected Inventor group node (e.g., SoSeparator, SoGroup) by specifiable Inventor group. All connections to the original Inventor group node are restored to the new Inventor group node.

4.8.2. Run User Script...

Opens a browse dialog to load and run a user script. By default, the folder MeVisLab/IDE/Modules/IDE/UserScripts is opened, where a number of commonly used scripts are located.

4.8.3. Run Last User Script:

Runs the last chosen user script. This menu entry is only active if a user script has been executed before.

4.8.4. Run Recent User Script

Offers a list of recently executed user scripts to choose from.

4.8.5. Example Scripts

Offers a list of pre-installed example user scripts.