Script Extensions

A script extension can be used as a library with a collection of objects, variables and functions. BPS itself contains several script extensions, for example bps and bps.gui which are documented for public use, bps.audit, bps.installer etc which are used internally by bps itself, and samples amd samples.reports as simple examples.

Technically extensions can be written as c++ plugin, as plain script or as a combination thereof. The bps and bps.gui are examples of extensions combined by a c++ plugin (plugins\script\bpsscript.dll and plugins\script\bpsscrgui.dll) and of scripts (plugins\script\bps and plugins\script\bps\gui). This article only handles plain script plugins. If you plan to use C++ for your extension please read about it in the Qt documentation.

When creating your own extensions, take care of the following naming conventions:

  • Name your plugin so that it does not conflict with standard bps plugins. For example if your company is ACME Corp, use plugins such as acme, acme.interface etc.
  • Plugin names must match the constraints of JavaScript variables. Do not use any blanks or special characters not allowed in a variable name, and start all parts of the plugin path names with a character allowed as first character of a JavaScript variable name.

Create your first plugin by creating a folder under the BPS plugins/script directory, and then create the extension script with the standard name __init__.js:

C:\Program Files\IBK BPS 2.19.0\plugins\script\test1\__init__.js:

__setupPackage__(__extension__);   // initialize extension
var ext = eval(__extension__);     // create shortcut for this extension
ext.version = '0.0.1';             // create a variable
ext.hello = function(aName)        // create a function
    print('Hello '+aName);

Now lets explain this:

<grid> <col xs=“4”>__extension__</col> <col xs=“8”>A predefined variable with the extension name. In this example the variable holds “custom”, in a sub-extension it may be “custom.interface” for example. Using this variable instead of the name directly is helpful if you ever need to rename, move or clone your extension, because the following script content is then independent of the actual extension name.</col> </grid>
<grid> <col xs=“4”>__setupPackage__ (__extension__);</col> <col xs=“8”>A convenience function for setting up a “namespace” in the script environment. A typical application is to call __setupPackage__() with __extension__ as argument; e.g. __setupPackage__(“custom.interface.import”) would ensure that the object chain represented by the expression custom.interface.import exists in the script environment.</col> </grid>
<grid> <col xs=“4”>var ext = eval (__extension__);</col> <col xs=“8”>The variable is a shortcut to the object (or namespace) “custom” that was created by the previous __setupPackage__ call. Instead of this shortcut you could as well access the namespace explicitely, but then you loose the code independance of the script name of cause.</col> </grid>

The rest are examples how to create a variable and a function within the extension.

Next create a script to test the extension:


importExtension('test1');         // load my extension
print(test1.version);             // use variable in my extension
test1.hello('Peter');             // use function in my extension

Run the script:

D:\myscripts>bps testext1
Hello Peter


As explained before it is possible to order extensions hierarchically, and the higher up (parent) extensions are assumed to be required for the sub-extensions. Qt Script will automatically load the parent extensions in advance when you load a sub-extension. For example


will let Qt Script first load extension a, then b and finally c. So by this one line you make all elements of the three extensions available to your script.

It is however important to have a minimal __init__.js in all extension directories even if no functions or variables are exposed by the extension. A minimal __init__.js should contain the line


In the previous article we told that storing any custom scripts in the BPS installation directories is not recommended, and same is true of cause also for extensions.

Basically what we need to do is create an additional plugins directory and tell BPS to also look there for extensions.

Our directories shall be organized as this:

D:\myscripts Our main scripts are here
D:\myplugins\script\myexts Our root extension with general purpose functions
D:\myplugins\script\myexts\test2 Our special purpose extensions go all below D:\myscripts\script\myexts

Create the directory D:\myplugins\script

Create the directory D:\myplugins\script\myexts and create file __init__.js in it:

var ext = eval(__extension__);     // create shortcut for this extension
ext.version = __extension__ + ' 0.0.1';   // create a variable

Create directory D:\myplugins\script\myexts\test2 and create file __init__.js in it:

__setupPackage__(__extension__);   // initialize extension
var ext = eval(__extension__);     // create shortcut for this extension
ext.version = __extension__ + ' 0.0.2';   // create a variable
ext.hello = function(aName)        // create a function
    print('Hello '+aName);

Create the test application D:\myscripts\testext2.js:

importExtension('myexts.test2');  // load
print(myexts.version);            // use variable in my extension
print(myexts.test2.version);      // use variable in my sub-extension
myexts.test2.hello('John');       // use function in my sub-extension

If you run testext2 now it is not surprising that you get an error message, because BPS yet knows nothing about the custom plugins directory:

The trick is to declare a custom Plugins path in section [Paths] of the bps.conf file:


<callout type=“info” icon=“true”>Up to 2.19 a custom Plugins path needed to be set in a manually created qt.conf file. However starting with 2.20 qt.conf is created automatically during software installation and holds the default plugins path which can not be changed, otherwise the platform pluging introduced with Qt 5 will not get found.

Therefore from 2.20 you must set a custom Plugins path in bps.conf. </callout> <callout type=“info” icon=“true”>Forward slashes are used here in the path. When using backslashes in a .conf file path they would have to be doubled, for example


</callout> <callout type=“info” icon=“true”>Instead of directory on a local disk you could also use a network share:


However be aware that BPS execution will be blocked whenever the network share is unavailable. For best robustness it is recommended to put the custom plugin directory on a physical disk on the same machine where the BPS software is installed. </callout> So now it should work:

  • scriptexts.txt
  • Last modified: 2020/04/09 11:39
  • by ibk