I am trying to create a button on a pop up window that would change a tag value and then close the window. The script and pop up close seem to work fine when I have them as the only action but the script won't write to the tags when both of the actions are on the button. I found a few posts that said this was a bug in Ignition and the actions actually run at the same time and not in a row, causing it to close before it writes. Has anyone found a work around to this problem?
- Don't use the Popup action to close the popup. Script it instead after your tag writes. See system.perspective.closePopup | Ignition User Manual. That way you guarantee the execution order.
- `system.tag.writeBlocking' accepts lists of tags and values. You can then write to them all at once. It's faster and less gateway load.
Thanks! I was not aware of the "system.perspective.closePopup" script. I am still struggling a little though. I have this code on a value change event script for the tag:
def valueChanged(tag, tagPath, previousValue, currentValue, initialChange, missedEvents):
if currentValue.value == False:
system.perspective.closePopup(12345)
and this is the code to open the pop up
if currentValue.value == 7:
system.perspective.openPopup(12345, 'Page/program7Popup')
The page seems to still not want to close.
This started off as a question on a button script.
Now it has changed into a script on a tag event!
- Tags don't know anything about sessions and what views / popups you have open. They don't even know if any client has the project open.
- In your code you are treating currentValue.value as boolean in one instance and integer in another. There seems to be some confusion in someone's thinking.
if currentValue.value == False:
can be written asif not currentValue.value:
You need to trigger popup opening and closing from changes in your application, not in tags which are on the gateway. You could bind a component or custom property in your application to a gateway tag and trigger an onChange event on the component / property - but not on the tag itself.
I changed it up and have the 'Popup active' tag bound to a cutsom property and I have a change script on that custom property that looks like this:
def valueChanged(self, previousValue, currentValue, origin, missedEvents):
#Current_Program_Number writes turns activePopup true when prgrm = 7, Buttons turn it flase when click
if currentValue.value:
system.perspective.openPopup(12345, 'Page/program7Popup')
elif not currentValue.value:
system.perspective.closePopup(12345)
but now the pop up won't even pop up
- Have you confirmed that your 'cutsom' property is actually changing? Add a label to your view and bind
props.text
to the custom property to monitor it. - What values does it give?
- Why are you using a tag to (now indirectly) control a popup? Have you considered what happens when multiple clients are open?
-
Yes the property is flipping correctly with the tag
-
It is a boolean, giving either true or false:
-
Each client will be unique based off of its IP address. I have a query that looks up the current IP address and assigns it based on a table, then each tag path I have set up indirrectly so it will know each machines tags
Is my problem that I do not have a unique pop up ID, for a specific session?
What component is the custom property assigned to?
I still don't understand why you're using a tag to control the activePopup. Do you pass this value to the machine somehow? If not then activePopup should be a session.custom
property.
It is assigned to the root of the pop up.
The tag is only a memory tag that I am writing to when another tag is a value that I want the pop up to happen on.
But if the popup isn't open it will never read the custom property. You need to add the custom prop and event to the calling view.
The tag is only a memory tag that I am writing to when another tag is a value that I want the pop up to happen on.
You can still do that with a session variable.
I switched the pop up script to the root of the main page and it seems to work now, thanks!