I am trying to setup a popup to open when a tag is 1 and close when a value is 0. Here is the code I am using. Right now I am just closing all windows to see if I can get anything to close. I am unable to close windows, this is in a client tag change script. Why can I not close the window but I can open it.
I ran the same code on a button script and everything closed, so I expect this to be an issue with it being in a client tag change script.
if(event.getCurrentValue().getValue() == 1):
window = system.nav.openWindow('Popup Window')
system.nav.centerWindow(window)
else:
windows = system.gui.getOpenWindows()
for window in windows:
system.nav.closeWindow(window.getPath())
Hi, maybe you’ve solved this by now since you seem to get what’s wrong with it.
This is what worked for me:
Create a Tag Change Script under Vision-Client Events.
The script’s “Change Triggers” should be Value only to make sure it only executes when you want to.
Under “Tag Path(s)”, choose the tag you want to monitor
On the Script tab, your script should look something like this:
#Check if your tag value is correct
if newValue.getValue() == 1:
window = system.nav.openWindow('Popup Window')
system.nav.centerWindow(window)
else:
windows = system.gui.getOpenWindows()
for window in windows:
system.nav.closeWindow(window.getPath())
Some considerations:
If your tag value can change while you don’t have a client running, you might encounter a situation where the your popup won’t open because the client wasn’t there to check the initial change.
If you want more information about scripting scope, you can check out this page where it mentions scripting scope: https://docs.inductiveautomation.com/display/DOC81/Scripting+in+Ignition
If you’re in doubt where your script function falls under the scripting scope, you can check out the function’s page where you can see it under Syntax: https://docs.inductiveautomation.com/display/DOC81/system.nav.openWindow
Right, I got all this. I am using the same code as you in a Vision Client Tag Change Script and I have a Client Open, But when the tag changes to 0, the windows do not close. That’s my problem
I did some tests and discovered that the code works if you change the function name from “system.gui.getOpenWindows” to “system.gui.getOpenedWindows”. Also discovered that the elif that i’ve used is unecessary since there’s no problem with the evaluation.
You can also change the .getOpenedWindows to .getOpenedWindowNames and you won’t have to use window.getPath() later.