Call project script from tag change

Hi,

I’m trying to create a simple logger for maintenance troubleshooting. Whenever I call from actionPerformed on a button or the scripting console everything works fine, but when I try to tie it to a tag change nothing wants to cooperate.

Am I calling this right or missing a step somewhere? Any help would be greatly appreciated.
My setup is Ignition 7.8.2, Java 1.8.0_77, 2012 R2 with a win7 client

Thanks

Project Script (project.testLog):

def opsLog(label,valueOld,valueNew):
	#Log sep. by day
	logpath = "C:/logs/Top Line/%s.txt" % str(system.date.format(system.date.now(),"yyyy-MM-dd"))
	logtime = system.date.format(system.date.now(),"HH:mm:ss.SSS")
	dashbreak = "\n-----------------------------------------------------------------------------------\n"
	writedata = "\n%s\t%s\tchanged from %s to %s" % (logtime,label,valueOld,valueNew)

	#Redundant create log if none exists, normally handled by autolog.rb
	if not system.file.fileExists(logpath):
		logbegin = str(system.date.format(system.date.now(),"MMM dd, yyyy"))
		filepath = system.file.saveFile(logpath)
		system.file.writeFile(logpath,"\n\n%s" % dashbreak,1)
		system.file.writeFile(logpath,"\nTop Line Log %s" % logbegin,1)
		system.file.writeFile(logpath,"%s\n" % dashbreak,1)
		system.file.writeFile(logpath,"\nAll times Central with DST accounted for\n\n\n",1)

	system.file.writeFile(logpath,writedata,1) 

Gateway console output:
[attachment=1]Ignconsole.PNG[/attachment]

Call at tag change:
[attachment=0]TagCall.PNG[/attachment]

Hi! Welcome to the forums. :slight_smile:

Tag scripts are run in the gateway, while project scripts are run in the client. Two different scopes. A deeper meaning is that the gateway has no idea which project a script is in when you try to call it.

Using a Client Event Script of a Tag Change variety should help you.

Hello,

I have the same error, and by putting the script in the Client Event Script of a Tag Change variety it start to work perfectly.
The thing is that I want the script to run always, even if the client is not open.

Calling the script from the Client Event Script would only run the script when the client is open, is that correct?

You want to use a project-scope gateway tag change event script, not a tag event. See the description of contexts here.

Yes, I was doing that but it keeps trowing me an error: “Cannot create PyString from null!” and when I put the same in the Tag Change of a Client Event Script

Would the project should be in the global script library (shared)? I didn’t try that yet. I’ll do it right away

That sounds like a different problem. Note that scripts for tag events are like a custom component methods -- event details are supplied as arguments to the function, and those arguments are locals in that function scope. A tag change script isn't a function -- its details are supplied in an event object. You can't just take code from one and paste it in the other.

I am not using a tag event.
Maybe I’m not making myself clear, or maybe I’m not understanding.

Here I go again.
I have a script in Ignition’s Shared Script Module (global library) very simple, only inserts some records in a database.
I want to run this script in 3 specific times of a day (once per shift). So I’ve made a boolean expression tag and What I want is that when that tag’s value is = 1, run the global script.
I want that script to be run everytime, no matter if the client is open or not. The script should run every time the tag is = 1.

So what I do is create in the project’s gateway event script --> tag change script, a new tag change script that evaluates the value of my expression tag, and when is = 1, call the global script like this: shared.myScript.testScript()

This is what I do that throws me the “Cannot create PyString from null!” error in the logs.

You’ll have to show your code. We can’t read minds. (At least, I can’t.) Please use a triple-` on the lines before and after your code so it’ll format nicely (readably).

1 Like

I already make it work !!!

The problem was that for some reason the tags “currentDataTime” and “username” weren’t working.

Thanks!!

1 Like