A user script is either a single
.py Python file or an MDL
.script file (with a
.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
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
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.
Show Random Example Network
Opens and shows a random example network. This is mainly for testing purposes.
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.
Runs the last chosen user script. This menu entry is only active if a user script has been executed before.
© 2021 MeVis Medical Solutions AG