How to open a popup based on tag value?

I’d like to open a popup based on the value of a tag. I have tried this as a timer client and tag change client script, both with no luck. On the tag change script, if I change that tags value then I get the popup, but it’s like it’s not seeing the condition. any ideas what I am doing wrong or where I need to put this code

if “testPressureOut” > 15000:
system.nav.openWindow(‘SHP_popup’)
system.nav.centerWindow(‘SHP_popup’)
else:
system.nav.closeWindow(‘SHP_popup’)

Hi,

Your condition compares a string to a number which doesn’t make sense.

Maybe you mean this:

if testPressureOut > 15000:
    system.nav.openWindow('SHP_popup')
    system.nav.centerWindow('SHP_popup')
else:
    system.nav.closeWindow('SHP_popup')

Where would I put it? I’ve tried both client timer and tag change scripts

Yea, you can add that code in the Timer event (make sure it is RUNNING). This kind of gives you the whole picture:

Either one would work.

How are you getting the value of the tag?

Are you getting it like this:

testPressureOut = system.tag.read("[default]foler/folder/mytag").value

It works in the timer script on the page but ultimately i’d like the popup to be there as long as the value is > X, and go away when the value drops below X. Won’t this need to be in a client script so that no matter what page is currently open that it will always be checking this value?

you should be able to stick this in a tag change script. put the tag in the tag list for the tag change script. Then you need to modify the script that adam or mudge posted to fit your tag path and window name. I would also put some print statements to see what is going on.

print "start script" testPressureOut = system.tag.read("[default]foler/folder/mytag").value print testPressureOut if testPressureOut > 15000: print "pressure greater than 15000, open window" system.nav.openWindow('SHP_popup') system.nav.centerWindow('SHP_popup') else: print "pressure less than 15000, do nothing" system.nav.closeWindow('SHP_popup')

Yes. Put it in a client script. The documentation says how to get the new value that changed: inductiveautomation.com/support/ … cripts.htm

From the Ignition User Manual:

print "Received tag change event for %s" % event.tagPath
value = newValue.value
quality = newValue.quality
timestamp = newValue.timestamp
print "value=%s, quality=%s, timestamp=%s" %(value, quality, timestamp)

i’m still not having luck with it, I’ve even tried different tags just to make sure and I’ve even deleted and recreated that test mem tag (testPressureOut). hmmm

Try using event.newValue in the Tag Change event:

testPressureOut = event.newValue

try:
	if testPressureOut > 15000:
		system.nav.openWindow("SHP_popup")
		system.nav.centerWindow("SHP_popup")
	else:
		system.nav.closeWindow("SHP_popup")
except:
	#window is already opened/closed
	pass

you do have the testPressureOut tag in the tag change script tag list under the tag tab in your screenshot right? also, that print statement needs to be "print testPressureOut", not "print testValue". thats probably why it is failing, because it doesnt recognize that variable.

Hey diat150 yes, I noticed that typo and corrected. Now the script runs and everytime I change that testPressureOut value I get the popup, regardless of whether or not it’s above or below 15000. weird…

this code worked good:

print “start script”
testPressureOut = system.tag.read(“testPressureOut”).value
print testPressureOut
if testPressureOut > 15000:
print “pressure greater than 15000, open window”
system.nav.openWindow(‘SHP_popup’)
system.nav.centerWindow(‘SHP_popup’)
else:
print “pressure less than 15000, do nothing”
system.nav.closeWindow(‘SHP_popup’)

thanks!

Anyone have any idea on how to do this on a mouse click script? I have a graphic that I want to run a mouse clicked script on… where if the tag is =1 I want one pop-up to open, and if it’s =0 I want a different pop-up to open.

I’ve tried this:

selectONE = system.tag.read("[]/MyTag").value

 if selectONE=1:
 system.nav.openWindow('ThisPopup')
 system.nav.centerWindow('ThisPopup')
 else:
 system.nav.openWindow('ThatPopup')
 system.nav.centerWindow('ThatPopup')

it borks out on an EOF on if selectONE=1

Thanks!

Try using the equal comparison (==) in python:

selectONE = system.tag.read("[]/MyTag").value

if selectONE==1:
	system.nav.openWindow('ThisPopup')
	system.nav.centerWindow('ThisPopup')
else:
	system.nav.openWindow('ThatPopup')
	system.nav.centerWindow('ThatPopup')

Also, make sure you have your Tag path correct. Try this, too:

selectONE = system.tag.read("MyTag").value

if selectONE==1:
	system.nav.openWindow('ThisPopup')
	system.nav.centerWindow('ThisPopup')
else:
	system.nav.openWindow('ThatPopup')
	system.nav.centerWindow('ThatPopup')

Thanks for the advice… I did a Homer Simpson on the Python ==. In any case - still errors out on me:

[attachment=0]Error.jpg[/attachment]

There’s probably another way to skin the cat :open_mouth:

Hi,
You have a simple Python syntax error. You have a couple spaces in front of “if AerationSelect==1:” that needs to be removed.

You need to make sure that the spacing and indentation of the Python code is correct.

Best,
Nick

# Open pop-up based on whether B8700S is selected for Membrane or Bio aeration
#
# Start script - assign alias to tag
AerationSelect=system.tag.read("CSWT1MB/BLOWERS/Global_Blower_Setpoints/pbB8700S_Membrane_Aeration_Select").value
# Check alias value
if AerationSelect==1:
	# If aliased tag = 1 then B8700S Selected for Membrane Aeration - open Train Blower pop-up populated with B8700S info
	system.nav.openWindow('Program Windows/Popups/puTrainBlower', {'BlowerID' : 'B8700S_HMI', 'TagPath' : 'B8700S_Info', 'TagID' : 'B8700S_Control'})
	system.nav.centerWindow('Program Windows/Popups/puTrainBlower')
else:
	# else B8700S Selected for Bio Aeration - open MBR Blower pop-up populated with B8700S info
	system.nav.openWindow('Program Windows/Popups/puMBRBlower', {'BlowerID' : 'B8700S_HMI', 'TagPath' : 'B8700S_Info', 'TagID' : 'B8700S_Control'})
	system.nav.centerWindow('Program Windows/Popups/puMBRBlower')

The word SyntaxError means that you wrote some code wrong. (In this case, it was the indentation on line 6) You’ll get it eventually; it just takes time if you’re new to this sort of thing.