Skip to main content
The following topics describe the framework for creating a Python-based node plugin.

Basic Requirements

The following requirements must be met for optiSLang to detect, load, and execute a plugin you provide.
  • Use the following naming convention for the script files: *_cn.py.
  • The required functions must be implemented in one script file.
  • Place the scripts in a directory scanned by optiSLang. Custom nodes found in any of these locations are loaded when the application starts and are then available within optiSLang. There are several location options:
    • The default custom node plugin folder belonging to the installation: [installation path]/scripting/node
    • An alternative customized integrations directory specified in the SC_AlternativeCIDirectories entry of the optiSLang configuration file.
    • An alternative customized integrations directory specified by the environment variable OSL_ALT_CN_SEARCH_DIRS

Functions to Implement

You can add a plugin for extending optiSLang by providing a Python file following a special naming convention and by implementing a set of functions within it following special naming and signature conventions. The following are the available functions forming the interface and indicate where implementation is necessary or optional. The execute_custom function is only required when you need advanced interactivity for user interfaces with QML-based settings. Otherwise, it is optional. You do not need to declare anywhere explicitly the set of functions you are implementing. The code in the top-level cn.py file is the declaration. Based on the presence of function implementation, optiSLang creates the nodes. When you add or remove functions, you can trigger optiSLang to rescan the libraries by closing and restarting it. The following functions are available:

execute

This function is used to call your solver. Incoming Arguments Return Values

default_settings

This function defines the set of default settings associated with each new node instance. In a dictionary, you supply name-value pairs. The value type is important, for example, by forwarding a boolean value this setting is determined to be a boolean switch. Your code should then not set any other value type later. Without supplying any QML code for drawing user interface elements, optiSLang will add generic user interface elements, and these are determined by the value type given here. For instance, a boolean value induces optiSLang to display a check box in the node edit dialog box, whereas for string values a text entry field is created. The value types supported are boolean, integer, float, and string. This function returns a list of zero to two elements, where each element can be either a Python object or a list of tuples. If you intend to use the generic settings user interface only, a planar dictonary (name-value pairs) or a list of tuples is supported. If you intended to use QML code, the elements can be nested Python objects. By providing a list of tuples, you can preserve the order of the given settings. The first element is always treated as a set of settings that require a node reset when manipulated in the user interface (modifying_settings). The second element is treated as a set of settings where you do not need to reset the node after they are manipulated in the user interface (non_modifying_settings). Note: In default_settings, you define the sequence of setting names and value types for your new node type. In all other functions, the settings container stored with the node is input using arguments. Wherever settings are consumed, you assume the same dictionary/list structure (the same sequence of names and value types). Incoming Arguments Return Values
  • List with zero to two elements containing modifying_settings and/or non_modifying_settings as Python objects or lists of tuples.

execute_custom

This function serves as flexible, general-purpose, signal and information channel between the QML layer and the Python layer. When you access tabs, entries, and buttons in the QML-based settings user interface, the QML layer is running the process. If you need logic evaluation or other small computations, the QML layer allows for lines of JavaScript. However, if you cannot solve all settings-related work steps in the QML layer, then the execute_custom function allows you to trigger work in the Python layer and collect work results from there. The execute_custom function can be triggered from the QML layer using the following: