Unable to run Module classes under gateway event scripts

How come I am able to run scripts under Tools/Scrip Console but I cannot run the same script under the Gateway Event Scripts

It starts with an import and I have put a system.write.tags after the import to see if it wrote the date to a memory tag, nothing works.
Also have another scripts on a timer that uses only ignition python language and works every minutes.

What wrong with this picture?

The module is loaded and uses GDC as the document says, I don’t really use the C switch, no clients will ever use this, only the Designer and the Gateway.

Thanks in advance

There are many classes that don’t exist in the gateway – anything gui related. If you are trying to import anything like that, or anything that depends on them, it won’t work. You’ll have to show your code for more assistance.

You want to see the code?
Ok, weird, the question is reallly why is the code works under Scxript console but not under the Gateway script under a timer.

But ok, here is the code:

import axium.aws
path = system.tag.read("[default]RTAC/ExternalFolder").value
#axium.utils.showMessage(path)
axium.aws.sendData(path,“Ignition.csv”,1)
axium.utils.showMessage(“Done”)

So this code works under the Designer, but not under the Gateway scripts.
The logs shows: ImportError: No module named axium

But the module was loaded ok and the scope is : Alizent.jar

Seems that some characters were removed from my message so scope = “GDC”

Jar files loaded into gateway scope by modules are not available to scripts you write in the gateway scope.

It happens to work in client/designer because there’s only a single ClassLoader used, but in the gateway there’s a hierarchy and modules are loaded in their own ClassLoader, at the bottom of the hierarchy.

Your module should instead expose its own scripting functions that then make use of the JARs you’re trying to use.

Alternatively, you can try to properly package the jars you need into the lib/core/gateway directory of your Ignition installation, but this isn’t quite supported/endorsed. There’s other posts in the forum about this approach.

1 Like

The gateway has strict classloaders. In the gateway, by default, module jars are not visible outside the module itself. A module developer would expose specific functionality by installing script functions into the system.* namespace. In the designer and client, all jars are loaded in the same classloader, so the script console can see those classes.
Alternately, you may use the “export” definition for the jar in your module, which will expose it to the rest of the gateway. But beware – such jars cannot be unloaded or replaced without restarting the gateway. See the specifications for module.xml files.

The hierarchy is:
SRClassLoader
-- Exports ClassLoader
---- Module ClassLoaders

I don't think exported jars are available to the entire gateway, just to other modules. I could be wrong though...

As could I. I never use export. I always deliberately expose what I want via the script manager.

I guess if one was in a hurry, a module could expose a single script function that returns the module’s classloader. Then scripts could use it to look up classes by name.

This is simultaneously clever, amusing, and horrifying :laughing: :cold_sweat:

1 Like

Well, yeah. I guess my disapproving tone of voice didn't come through.... the "one" who is in a hurry in that scenario is definitely not me.