How to trigger script written in project library

I have created a simple gateway event script for testing.

def test:
      a =1
      b=2
      c = a+b
      print c

test()

And i have named this script as Test
After saving the script, i have waited for this to execute automatically but didnt work.

if i run the same script in script console, it is working… I believe there is nothing wrong with this test script.

I just wanna run this Test script automatically, Anyone pls tell me how to do that?

When you create a gateway event script you have to choose what event is to trigger it. Your options are:

  • Startup
  • Update
  • Shutdown
  • Timer
  • Tag Change
  • Message
  • Scheduled

Which did you choose and what was the trigger?

okay,
I have created the Test script under the Scripting section,

Could you pls tell me to run that script?

That’s a library script, not an event script. Library scripts don’t run unless an event calls a function within them. One of the events @Transistor listed.

Edit: Also note that when you have an event that calls Test.test(), the first time will yield two calls to test(), since you include a call at the top level of the library script. The top level runs once, to completion, the first time any member of it is accessed. (Like an auto-import.)

Another thing to note here is that print 'hi' in the gateway context - you will never see this.

You need to use a logger to log your messages to the gateway.

def test():
    logger = system.util.getLogger("My Logger")
    a=1
    b=2
    c =  a + b
    logger.info("Value of c is %i"%(c))

is how you would be able to see results in your gateway logs.

You need to be more precise in your writing. Your question title says "event script". I now suspect that you mean you have written it in the Project Library.

You can run a Project Library script from a button.

  • Right-click the button.
  • Select Configure Events ....
  • Select onActionPerformed, hit + and select Script.
  • Add the path and name of script.
1 Like

Thanks,
I was doing it in multiple ways, forgot to rename it.

If anyone else forgot like me - syntax of the path and name of the script is not as the project browser "copy path" feature gives - need to change slashes for dots.
So not Folder/Subfolder/Library_Script.method(args) but Folder.Subfolder.Library_Script.method(args)

Edit: Project browser tree copy path. Didn't know there was a similar tool in the script editor!

1 Like

In new-ish versions of Ignition, the auto complete (Ctrl+space) will provide you paths to your project library functions.

Thanks, yeah. Even without ctrl+space, 8.1 does propose completions if you start typing but if you paste an invalid path after copying one then it it does not.

What ? Where are you copying it from ?
Mine gives the proper path:

image

lib.dict.sanitize_keys(dic, sfunc=make_key, recursive=True)

1 Like

Probably from the project browser menu. I can see how that would be confusing.

1 Like

Right, didn't even notice you could get a path from there. Not sure what it would be useful for though ?

1 Like

Mostly useful for Vision windows, but probably a generic action added to an abstract tree node class, so everything gets it.

1 Like