Hello everyone
I have a popup window, and I want it to appear when a tag changes from false to true.
I also require it to appear on a defined window, as I have 4 different windows, but I don’t want it to appear on all of them.
Hello everyone
I have a popup window, and I want it to appear when a tag changes from false to true.
I also require it to appear on a defined window, as I have 4 different windows, but I don’t want it to appear on all of them.
In the defined window, add a custom property to the root container and bind that tag to it. Define a propertyChange event on the root container that opens the popup when that property becomes true.
hello @pturmel
thank you very much.
I already added the ‘propertyChange’ event in the window where I want it to appear, but the popup window appears in other windows.
A propertyChange event must always have one or more checks for the correct event.propertyName
. I don’t see that in your screenshot.
Also, your if statement will never be true, since you are comparing a constant string against a constant integer. Bind the tag to a custom property. (A string containing a tag name doesn’t magically become the tag value.)
You code runs when any property of that component changes. That is certainly wrong. Use an if
statement to compare event.propertyName
against the property that should be triggering your code. Everything else (everything you have now) should be indented under that if
statement.
do you have an example?
Examples all over this forum:
https://forum.inductiveautomation.com/search?q=event.propertyName
Use the custom property name to which you bound your tag. No need to read the tag in your script since its value is in the custom property.
as a fun exercise, add this into your propertyChange event handler code:
print 'PropertyChange name: ', event.propertyName
Then save, close the resource, open your console in your designer or your client, and open the page again and see the number of propertyChange events you see. This will show you why you need to single-out the property name you’re looking for with:
if event.propertyName == 'property name':
When doing this, I also followed your other comments about something with only caring about one property changing, but before and after I added the propertyName into my code, I still continued getting the message box that I have to pop open, about 3-5 times popping up before it stops everytime I open the window that has the propertyChange script in it.
Below is my code. I assume you have experience with what I am talking about.
Basically I am trying to get the IP address of a screen that I am using to compare which screen it is, first screen to access that page or second. If it is the second screen, click a button to gain access and write over those tags that stored the previous ip addresses. Once the ip address is the same, pop open a message box that access has been granted...
My main issue is ONLY that it pops open as I said 3-5 message boxes once I open that screen until it stops, then doesn't do it again until that screen is opened again.
# Check if the changed property is the custom property we want
firstUserIP = system.tag.readBlocking(["[Path]tempTags/sCurrentUser_IP"])[0].value # Adjusted to retrievethe actual tag value
secondUserIP = system.net.getIpAddress() # Adjusted to retrievethe actual ip
if event.propertyName == "ScreenNumber":
newValue = event.newValue
# Check if the current IP is different from the first user IP
if firstUserIP != secondUserIP:
system.gui.messageBox("Someone else is on the page")
#system.nav.closeWindow("Main Windows/TheScreenTest")
else:
system.gui.messageBox("Access granted")
# Display the new value of the property
system.gui.messageBox("The new value of ScreenNumber is: " + str(newValue))
if event.propertyName == "ScreenNumber":
I would print or log the value of this proprety somewhere, your newValue
variable. Perhaps this ScreenNumber is changing more than you think, triggering this more than you expected.
Well I do have it binded to a tag, that when i press the button, it assigns a value desired. Yet continues to pop open a few messages when i open that window again. When I click ok on all of them, the screen does actually do what I want. I assume some sort of property changes on all properties when the window is closed AND opened...Wonder if there is a way around this.
You are performing work in a propertyChange event (readBlocking, getIpAddress) before checking the event's propertyName. Don't do that. Don't do any work in a propertyChange event outside the if
block.
How else do I define it inside the "if" if I have to define it prior to my code inside the second "if", yet highlights the second line "secondUserIP" as if it is not indented or formatted correctly.
EDIT: Even after removing the "secondUserIP" line, it still continued to do this after putting in all work inside the "if propertyName" anyways
Your yellow highlight is just below a red squiggle that indicates a jython syntax error on that line.
You aren't showing the whole code on that line, so not resolvable by us.
Also, you should not be using system.tag.readBlocking()
in a Vision event script at all--it makes a potentially slow callout across the network that can freeze your client. Bind that tag to another custom property (tag binding) and check that property in your event script.
Let me add:
The code shown suggests that you are attempting to deny access to something after it has already happened. (Screen number that someone else is using.) This is a problem, as the only practical way to deny access is to do it before it happens. Your code shown just pops up messages, but doesn't actually deny any access.
Both Vision and Perspective have security controls that can be attached to Windows/Views to actually prevent usage. Pretty much all other navigation control cannot be stopped. Which means the operation that you can actually impact is use of input fields. By disabling them with bindings (not scripts) appropriate to the situation.
Consider an alternate approach. (And share more, so we can help more effectively.)
Final Note: In Vision, consider not using IP address to identify various workstations. Use the client's unique ID in your algorithm above. And, where specificity is required, use Ethernet MAC ID instead of IP address. Much more reliable identity.
I agree that it is more practical to use the client id as opposed to IP address, however, the project I am working on is requesting that when the second client enters the same screen that the first client is on, to kick off the first person instead of blocking it out prior to entry...I came back to this as I had a few other tasks to do but this was a discussion I posted about a month ago and yes, I understand that a message box doesn't actually close anything, but when both screens overcome the overload of message boxes, it works exactly how I want, the message boxes appear on the correct screens as desired and "access granted" message appears where I want it. By logic, if I get the message boxes to stop spamming the screen when initially entering the screen, it then can be utilized to kick the first user out as intended similar to how the first screen will get the "someone else using screen" and second screen gets the access granted message. As this will mean that I managed to get it to stop running the propertyChange event 3-5 times prior to even entering the screen and getting a chance to run it correctly as intended
Currently I have a button that on release, performs this and as mentioned, functions correctly as well as allows my propertyChange script to run once and how I want it once actually overcoming the spam of message boxes:
# Retrieve the IP address of the client
active_ip = system.net.getIpAddress()
# Define the tag path where the IP address will be stored
tag_path = "[Path]tempTags/sCurrentUser_IP"
# Write the IP address to the specified tag
system.tag.writeBlocking([tag_path], [active_ip])
if active_ip == '10.77.07.10':
system.tag.writeBlocking("[Path]tempTags/iScreenNumber.value", 1)
elif active_ip == '10.16.05.11':
system.tag.writeBlocking("[Path]tempTags/iScreenNumber.value", 2)
elif active_ip == '10.16.05.12':
system.tag.writeBlocking("[Path]tempTags/iScreenNumber.value", 3)
elif active_ip == '10.16.05.13':
system.tag.writeBlocking("[Path]tempTags/iScreenNumber.value", 4)
Fixed that for you.
Consider not using any popups. Just a visionWindowActivated script that writes the current client ID to the appropriate tag in the gateway.
In the Window's root container, bind that tag to a custom property. In another custom property, a boolean, called permission
perhaps, use an expression to compare that tag value (via the bound property) to the current client ID (in the system provider). Tie the enable property of all input fields to that root container permission
property.
Any time that window is opened, anywhere else it is open will simply go grey.
Thank you so much for your help. Ill take a look at this tomorrow.