Register scripts as modules
In Python it is possible to call functions and classes from other scripts. Functions and classes that are used more often or in several scripts can be centralized in a separate script (module).
Scripts are also used as modules for Custom Renderer and List Controller, as well as for customer-specific adjustments of Resource Planning and of Interfaces (Extensions).
A module is created like a normal script via folder Settings > Reports & Scripts > Scripts: Right-click New > Script.
The following properties are relevant for modules:
Designation |
Since the designation is used as name of the module, it must not have spaces or umlauts in their names. It is best to choose a designation that gives an indication of the content, so that you can easily identify which module is used. Note that Python is case-sensitive, so the module must be called in the same way the designation is defined here. |
Platform |
Select wheter the code is implemented in Python 2 or Python 3. |
Extended rights |
Modules can be run with Extended user rights. Note that extended user rights during the execution take effect system-wide, even if you call something from another module in a script. |
Script text |
This is where the Python code is located. See the section Code in scripts as modules below. |
Script Editor... |
Opens the script in the Script Editor. The Script Editor is then directly linked to the script. This means that if code is modified in the Script Editor, the script text in the script also changes. |
Classes and functions can be defined in modules.
def functionname():
...
Parameters can be passed to the function in brackets. Functions without parameters are defined with emplty brackets.
To call a function from another script (module), the module must first be imported:
import modulname
The module name corresponds to the designation of the script (see above). The function is called via
modulename.funktionname
import modulename modulename.functionname
class classname:
...
If the class inherits from another class, it can be passed in brackets:
class baseclassname:
...
class classname(baseclassname):
...
Functions can be defined within the class. If functions are to be used within this class, both the module and the class must be imported:
from modulname import classname
Custom Renderers, List Controllers and Resource Planning descriptions specify which functions you can and must use.
If a module is modified, it is reloaded the next time it is called within the same session.
Other sessions detect the changed script code via Notif Server, but do not reload the module. In this case either Vertec must be restarted or the module must be reloaded with the command reload(modulname). Either in the Script Editor or directly in the script:
import modulename reload(modulename)