Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.



What

is

Is Scripting?

Most of the time when we talk about "scripting" in Ignition we 're are talking about Python scripting, or writing code in the Python language. Python is a general purpose programming language that was developed in the early 90's 90s and has gained significant popularity in the 2000's2000s. We like it because it is extremely readable, elegant, powerful, and easy to learn. As an added bonus, it gracefully interacts with Java, giving programmers an extremely powerful tool when paired with Ignition, which is written in Java.

Since Python is such a popular and well-regarded language, there are many high-quality tutorials available on the web. The official Python tutorial, written by the inventor of Python himself, Guido van Rossum, is very good.a great reference: https://docs.python.org/2/tutorial/index.html. In Ignition, you will be mixing the core Python language with references to other components and a variety of our built-in system functions.

Code Block
languagepy
titleSample CodePseudocode - Interacting With a Component
text = event.source.parent.getComponent('TextMy FieldComponent').text
if text == "":
	print "You must enter a name"
Is it easy to use



On_this_page



Is It Easy to Use?

Luckily, Python is a simple language to get started with, and using it in an event-driven system takes away a lot of the extra code that normally makes programming time consuming. For those that are already familiar with scripting (and those of you that are learning), we also have a huge list of functions inside Ignition to do some of the common tasks in a single line of code. These System Functions are available while typing. Just start with "system

.

" and press "ctrl-space" to see a list of available functions. The list will filter itself as you continue typing.

Image Modified

Where

is

Is Scripting Used?

Python is used in many places in Ignition. Each location has

it's

its own events that trigger your scripts to run, and add functionality to your projects in different ways.

  • Components - Add actions to components like buttons, customize the look and feel of charts and tables, and even setup a custom navigation schema.
  • Tags - Create a script that runs on a
tag
  • Tag change, when an alarm goes active, and more!
  • Reports - Use scripting to create a customized datasource, or create your own unique action to use with the scheduling system.
  • Alarm Notification - Create custom rosters using scripting
,
  • to dynamically change who gets notified with each new alarm event.
  • Client and Gateway - Add a script that will run when certain events happen, such as when the Client or Gateway starts up, or on certain keystrokes.

Users that are new to Ignition focus mainly on the Component Binding system, and for good reason. It's simple, flexible, and generally easy to understand without much of a computer background. However, Ignition has a complete scripting system built into every place you can think of. Using it is not a requirement, but it can add a significant degree of flexibility and customization to your projects. It allows you to create exactly what you need, giving you total control where pre-canned options fall short. 

The majority of your scripting will be done in Event Handlers inside of components. This system makes it very easy to get started scripting with little to no experience. With the four script builders, basic scripting like Navigation and setting Tag values takes just a few clicks!

on



next_
this_page Scroll HTML Exporter Ignore
Iulink
URLhttps://inductiveuniversity.com/video/system-library
NameSystem Library

 

Python or Jython?

You'll often hear Python referred to as "Jython" by advanced users of Ignition. Python is the language, Jython is the implementation of the language that we use. Most users of Python use the implementation called "CPython" - they just don't realize it. See http://en.wikipedia.org/wiki/Python_(programming_language)#Implementations.

One of the powerful things about using Jython is that your script has access to the entire Java standard library. In the Client, this will be Java 5 or above. When running under the Gateway, this will be Java 6 and above. For more information, see Accessing Java.

Many scripting users are blown away by their script's speed. We can't take credit for this - the Jython engine hot-compiles (compiles the code when it is run) your Jython code to Java bytecode, which means it runs natively in the JVM, which in turn can hot-compile it to machine code. It's fast.

Which version of Python is Used?

Ignition uses Jython 2.5. Jython is the Python programming language implemented over the Java Virtual Machine. When looking at outside documentation, such as on www.python.org, verify that you are looking at the correct version of the documentation.

Jython 2.5 allows us to use the standard functions and tools in Python 2.5, so if you want to look up something in the Python docs, make sure to use version 2.5 (https://docs.python.org/2/).

Why not VBA?

Many HMI/SCADA packages use VBA, or Visual Basic for Applications. As such, many engineers switching to our software inquire about it. There are a variety of reasons we don't use VBA:

  • It is not compatible with Java, the language that Ignition is written in. This also means that it is not cross-platform.
  • It is a dying language (Microsoft has phased it out as of July, 2007).
  • It is full of security holes.
  • It is an ugly language!