Skip to main content

Python (Jython) Scripting in Ignition

By NFM Consulting 2 min read

Key Takeaway

Guide to Python scripting in Ignition — script types, the system.* API, gateway vs. client scope, project library scripts, and debugging techniques.

Quick Answer

Ignition uses Jython (Python 2.7 running on the JVM) for all scripting. Scripts can run on the gateway, in client sessions, or in the Designer. Ignition provides a comprehensive system.* API for database access, tag operations, alarm management, HTTP requests, file I/O, and user interaction.

Scripting Contexts

Understanding where a script runs is critical in Ignition:

  • Gateway Scope — Timer scripts, tag change scripts, message handlers, and alarm pipeline scripts run on the server. They have no access to client GUI functions but can use system.db, system.tag, system.alarm, and system.net.
  • Client Scope — Component event scripts and client event scripts run in the operator's session. They can access GUI functions like system.gui (Vision) or system.perspective (Perspective).
  • Designer Scope — Scripts in the Designer's scripting console run in the Designer's JVM. Useful for testing and prototyping.

Common System Functions

# Read a tag value
value = system.tag.readBlocking(["[default]Tank/Level"])[0].value

# Write a tag value
system.tag.writeBlocking(["[default]Pump/Start"], [1])

# Run a database query
results = system.db.runQuery("SELECT * FROM production WHERE date = ?",
                              [system.date.now()], "ProductionDB")

# Send an HTTP request
response = system.net.httpGet("https://api.weather.com/conditions")

# Log to the gateway console
system.util.getLogger("MyScript").info("Process completed")

Project Library Scripts

Reusable functions should be placed in the project's Script Library (Project > Script Library in the Designer). These modules are accessible from any script context using the project name prefix:

# In Script Library module "utils"
def calculateFlowRate(dp, density, area):
    import math
    return area * math.sqrt(2 * dp / density)

# Called from any script
rate = project.utils.calculateFlowRate(15.2, 840, 0.0314)

Debugging Techniques

  • Use the Script Console in the Designer for interactive testing.
  • Use system.util.getLogger() to write to the gateway logs, viewable in Status > Logs.
  • Use print() statements for Designer output — these appear in the Designer's output console.
  • Check the Script Diagnostics page in the gateway for script errors, execution times, and call counts.

Frequently Asked Questions

Ready to Get Started?

Our engineers are ready to help with your automation project.