A project's Script Library is a library of scripts that can be called from anywhere within the scope of a project. These scripts are organized as named modules that live in the project package for project-specific scripts, and the shared package for global scripts. If you are upgrading from version of Ignition prior to 7.7.0 that had scripts in the legacy app package, those will be imported and will still be in the app package.
To open the Script Editing Workspace navigate to the Project > Scripts > Script Library [project] node or the Global > Script Library [shared] node in the Project Browser. In the Script Editing Workspace, choose Create 'Project' Script or Create 'Shared' Script. From the browser tree nodes you can also right-click and choose New Script.
Rule of Thumb: Never Copy-and-Paste a Script
If you're unsure of when to put scripts in a script module vs embedding the script directly in an event handler, follow this simple rule. If you ever find yourself copying a script from one event handler to another, stop and refactor the script into a project or shared script module! Then simply call your new script from the event handler. This rule will help prevent code duplication across your project, a major maintenance liability.
How to use Script Modules
To add a new script, simply select the project or shared package, right-click, and choose New Script. Each module is a Python script that may define many functions. You may also organize scripts in sub-packages if you'd like. Lets suppose you added a global script named myfuncs, whose body was:
Now, anywhere in your project you can call: