Accessing com.inductiveautomation.ignition packages in Python

Hi,

I’d like to use some of the helper functions scattered throughout com.inductiveautomation.ignition from within Python. In this specific case com.inductiveautomation.ignition.common has QualifiedPathUtils and I’d love to access the toTagPathNew method.

Is there a way of accessing the com.inductiveautomation.ignition packages? I’ve gone through the documentation and it mentions access Java libraries, but it’s not clear if or how I could access com.inductiveautomation.ignition packages?

I did seem to be able to import the package, but perhaps my syntax is wrong:

import com.inductiveautomation.ignition.common

QualifiedPathUtils.parsePossibleTagpathNew("prov:default:/tag:test/folder1/folder2:3/TEST420/DA_TEST:/alm:Low Low Test")

When running the above inside the Script Console, I get the following:

Traceback (most recent call last):
  File "<input>", line 4, in <module>
NameError: name 'QualifiedPathUtils' is not defined

If you import without the optional from clause, you have to refer to the imported objects by their full name. Such an import just makes the namespace available.
Use this syntax instead:

from com.inductiveautomation.ignition.common import QualifiedPathUtils

Note that jython cannot do wildcard imports of java classes. Each class you want to use must be named in an import statement.

1 Like

Let me elaborate a bit:

The import behavior you were expecting corresponds to java’s import something.something.*;. But in java, an import is really just syntactical sugar for programmer convenience. A java programmer can always spell out full class names without any import statement.

Python/jython doesn’t work this way. In python/jython, import is a fundamental operation that makes other packages available within the scope, optionally removing a package prefix or renaming the object into the new scope.

2 Likes

Brilliant @pturmel, this is really appreciative and opens up a lot more functionality! Thank you.