Introducing a hopefully community-engaged effort to build a useful repository of scripting and other Ignition utilities for everyone to benefit from.
Download the latest release from the Releases page and take advantage of the following functions:
Scripting Functions
system.util
system.util.getContext(): Context
A convenience function to retrieve the local "context" object, useful as an entrypoint to other advanced scripting.
system.util.deepCopy(object): Object
Converts a given Python object of any type into native Python data structures - lists, dictionaries, or "primitive" values (numbers, booleans, strings).
system.util.evalExpression(expression, **arguments): QualifiedValue
Evaluates the supplied string expression
as an expression. Additional keyword arguments to the function are provided as reference values inside the expression, e.g.
system.util.evalExpression("{one} + {two}", one=1, two=2)
Any other reference inside curly braces is assumed to be a tag path.
Returns a QualifiedValue.
system.dataset
system.dataset.print(dataset, output=sys.stdout, includeTypes=False)
Pretty-prints an Ignition dataset to the supplied buffer (or, with no argument, the local JVM standard output buffer). If includeTypes
is True, adds the simple name of the column's type to the header.
system.dataset.map(dataset, mapper, preserveColumnTypes=False): Dataset
Runs mapper
on every row of dataset
. mapper
will be invoked with keyword arguments, per column in dataset
. Return the new values for each row as a list or other sequence. This function allows you to perform multiple updates to a dataset, per-row, as a single operation.
system.dataset.filter(dataset, filter): Dataset
Runs filter
on every row of dataset
. filter
will be invoked with keyword arguments, per column in dataset
. The first argument will be the row index, as an int. Return True
to keep the column in the output, or False
to omit it.
system.dataset.fromExcel(input, headerRow=-1, sheetNumber=0, firstRow=-1, lastRow=-1, firstColumn=-1, lastColumn=-1): Dataset
Attempts to read input
as an Excel file (either from a filepath supplied as a string, or as a byte-array already read into memory). Looks on sheetNumber
for a contiguous dataset. Provide firstRow
, lastRow
, firstColumn
, and lastColumn
to restrict the region of cells read (if not provided, the first/last cells with data will be used). Pass a value for headerRow
to extract column names from a particular row (outside of your data region).
system.dataset.equals(dataset, dataset): Boolean
Returns True if both input datasets have the same columns, with the same types, and the same values.
system.dataset.valuesEqual(dataset, dataset): Boolean
Returns True if both input datasets have the same number of rows/columns, and those rows/columns have the same values in the same places.
system.dataset.columnsEqual(dataset, dataset, ignoreCase=False, includeTypes=True): Boolean
Returns True if both input datasets have the same column definitions. Use the optional keyword arguments to make the behavior more lenient.
system.dataset.builder(**columns): DatasetBuilder
Returns a wrapped DatasetBuilder. Provided keyword arguments (if any) are used as column names; the values should be Java or Python types, or the 'short codes' accepted by system.dataset.fromCSV:
alias | class |
---|---|
"byt" | byte.class |
"s" | short.class |
"i" | int.class |
"l" | long.class |
"f" | float.class |
"d" | double.class |
"b" | bool.class |
"Byt" | Byte.class |
"S" | Short.class |
"I" | Integer.class |
"L" | Long.class |
"F" | Float.class |
"D" | Double.class |
"B" | Boolean.class |
"O" | Object.class |
"clr" | Color.class |
"date" | Date.class |
"cur" | Cursor.class |
"dim" | Dimension.class |
"rect" | Rectangle.class |
"pt" | Point.class |
"str" | String.class |
"border" | Border.class |
In addition, the colTypes
function can now be called with the same short codes, or common Python types (e.g. str
instead of java.lang.String
).
system.project
system.project.getProject(): Project
Returns the internal project object appropriate to your local scope. On the gateway and the client, this is a RuntimeProject
; in the designer, this will be a DesignableProject
that can be directly mutated.
Also, on the gateway, getProject()
can be called with a single string argument to retrieve a project by name.
system.project.save()
In the Designer, essentially programmatically pushes the save button.
system.project.update()
In the Designer, programmatically invokes the 'Update Project' action, which pulls in changes to the local project from the gateway.
Expression Functions
Logic
isAvailable(value)
Returns true if the provided value (i.e. a tag reference) has a quality other than Bad_Disabled
or Bad_NotFound
.
anyOf(args...)
, allOf(args...)
, noneOf(args...)
Logical predicates across the input arguments, interpreted as booleans. Beware vacuous truth on empty lists of arguments.
Experimental
system.tag
system.tag.getLocalConfiguration(basePath, recursive=False)
Retrieves only the local configuration for the given tags under path, per the same browsing behavior as system.tag.getConfiguration; i.e., omits any content inherited from parent UDT(s).