Top | Previous | Next |
Script Libraries |
A script library is a collection of script modules that define functions which may be called from many places. If you have script logic that is used in more than one place, it is preferable to consolidate this logic into a script library instead of copy-and-pasting the script into multiple places. This way, the script can be maintained and updated in one place, which not only convenient, but less error prone because you cannot forget to alter all of the scripts.
Libraries project.* vs shared.* Your script libraries are all collected under one of two namespaces: project or shared.
The project script library is stored inside the project, and can be used by any scripts that are also within that project, for example, from component event scripts, or gateway/client timer scripts. They cannot be used from scripts stored outside the project, for example, tag event scripts.
The shared script library is stored in the gateway and is accessible to all projects, as well as tag event scripts.
Modules and Packages Scripts added to the script library are called modules. The folders they are stored in are called packages. Suppose you add a module called "MyFunctions" to the package "shared", and the source of your module looked like this:
LOOP_COUNT = 10
def printManyThings(): for x in range(LOOP_COUNT): print "hello world"
you would call your function from elsewhere in Ignition using this statement:
shared.MyFunctions.printManyThings()
If you had put this module into a sub-folder underneath "shared" called "utilities" then the statement would become:
shared.utilities.MyFunctions.printManyThings()
Legacy app.* Script Modules Prior to Ignition 7.7.0, the project.* and shared.* libraries did not exist. Instead, there was one library under the app.* namespace. These modules functioned in the same manner as the modern project.* library, except that they ran under the legacy Python 2.1 scope rules.
See also: |