Create Python Script by Importing Third-party or Custom Python Modules or Functions

About this task

This topic describes how to create a Python script by importing custom or third-party Python modules or functions.

Procedure

  1. In the same machine where you installed Python 3.8, install the needed modules or create your own functions.
  2. After you install the modules, for the collector to recognize the modules, update the following path to include the location where you installed the modules or created your own functions:
    Computer\HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\GE Digital\iHistorian\CollectorServiceExtensions\PythonExpressions\PythonPath
    After you update the path, the changes are reflected as follows:
    C:\Program Files (x86)\GE Digital\Historian Python Expressions\Python38\lib
    C:\Program Files (x86)\GE Digital\Historian Python Expressions\Python38\user
    C:\Users\Administrator\AppData\Local\Programs\Python\Python38-32\Lib
    C:\Users\Administrator\AppData\Local\Programs\Python\Python38-32\Lib\site-packages
    You can also configure Python library path using Configuration Hub. For more information, refer to Configure Python Library path using Configuration Hub.
  3. Access Configuration Hub
  4. In the NAVIGATION section, under the Configuration Hub plugin for Historian, select Tags.
    A list of tags appears.
  5. Select a Python collector tag, right-click or select more options, and then select Calculation.
    The PYTHON SCRIPT editor appears.
  6. In the scripting section, remove Null (and retain the Result =).
  7. In the scripting section, to import the custom or third-party functions/modules, enter the script in the following format:
    import mymodule
    Result=mymodule.myfunction()
    #Example
    import SimulationCalculation
    Result=SimulationCalculation.GetInteger()
  8. To test the function, select .
    A message appears, stating whether the syntax is correct.
  9. In the upper-left corner of the page, select Save.
    The Python script is created.

    After few seconds, the added script takes effect.