Create and Use Custom Libraries

You first need to create a custom library before you can use it to define a new item: function, function block or variable (for more details on library usage, refer to Use the Custom Library).

Create the Custom Library

  1. In the File menu, click the New command (save your current opened project if necessary)
  2. Select the Library application template

  3. Figure 4-34: Create a Custom Library - Select the Library Template

  4. Click the Finish button
  5. Click the Save As command in the File menu
  6. Define the Library Name (extension *.kal) and its Location
  7. Click OK
  8. In the Project Explorer, expand the Controller and PLC nodes
  9. Right-click on Subprograms and choose New UDFB in the contextual menu, then select the type of programming language
  10. Expand the Subprograms node and rename the new UDFB

    • It is the name of the variable type which is displayed in the dictionary if you use this library in another project.


    • Duplicate UDFB names in a library are not possible. Only the first instance found is kept when importing the library definitions in a project.

      To avoid this situation when designing your libraries, use a prefix to identify the library for all UDFBs and functions in the libraries (in the current procedure, the prefix is: NewLib_).

  11. Create the UDFB program (for more details, refer to Create Programs)
  12. In the File menu, click the Save command

Use the Custom Library

  1. Open the project where you want to use a library
  2. In the Project Explorer, expand the Controller node
  3. Right-click on PLC and choose Libraries in the menu
  4. Click Add

    • You can add as many external libraries as you want

  5. Select the *.kal file already created before and click Open
    Use a Custom Library - Select the Library
  6. Figure 4-35: Use a Custom Library - Select the Library


    • You can use the relative path to specify the path relative to the working directory where your project is saved. This ensures consistency when you move your project and your library.

      Conversely, the absolute path points to the same location on your file system regardless of your project directory.

  7. Click Close
  8. The library is displayed in the Library widget and you can now drag-and-drop the UDFB (or any subprogram) of this library in any editor
    Use a Custom Library - Display the Library
  9. Figure 4-36: Use a Custom Library - Display the Library

  10. In the Dictionary toolbox, right-click on the program and choose Add variable in the menu
    Use a Custom Library - Add a Variable
  11. Figure 4-37: Use a Custom Library - Add a Variable

  12. In the Type drop-down menu, select the type defined in the external library (it can be at the bottom of the list)
    Use a Custom Library - Select the Type
  13. Figure 4-38: Use a Custom Library - Select the Type

What happens when you remove a library from your project?

If you remove a library from your project, all its types are removed from your project and all variables based on the library are displayed in the dictionary in red with question marks

What happens when a library no longer exists?

If you open a project containing a link on a library which is no longer available, a warning is displayed:

To recover the libraries, you have two options:

  • Enter the new path to this library (assuming it still exists on your machine) using the library dialog (see Use the Custom Library).
  • Find the missing library and copy the library back to the path originally specified.
    Note that the project has to be closed and re-opened for the library to be read again.