I’m trying to troubleshoot a script that is supposed to open a popup window when the tag value changes to 1. I’m having a little trouble understanding what the person was doing. Combine that with my minimal programming experience and I am confused haha. The code is:
value = newvalue.value
path = str(event.tagPath)
compNum = path[len(path)-5:len(path)-4]
if value == 1:
win = system.nav.openWindowInstance("Popups/Compressor Status", {"CompressorNumber" : compNum})
system.nav.centerWindow(win)
I see that they’re defining their variable in the first three lines and then have an if statement after that. Without knowing exactly how the commands are supposed to be formatted, I’m a little lost. My first thought was that the window being pulled up is called Compressor Status and it is located in the Popups folder for windows. Is what is written, the correct way to format that? Or does is look different and not need the Popups/ part of the title?
Your first thought is correct. The {“CompressorNumber” : compNum} portion is where the compNum value gets written to the CompressorNumber property of the Root Container of the new window.
What is it doing (or not doing, as the case may be)?
Where is the location of the tag? If you need to pop up a windows, the tag needs to be a client tag.
It is not doing anything at all The tag is located in Tags> Refrigeration> Compressor1> hoa . Compressor1 is a UDT and the tag hoa is included within it. I don’t think that hoa is a client tag though, so I may need to start there. Can I just change the tag type or do i need to delete the tag and then recreate one with the same name?
The issue is that any gui stuff can only be triggered by client tags, and the script also needs to scoped to the client. “Regular” tags (for lack of better term) are scoped to the gateway, which has no gui operations.
I think this will be the least painful if you make this a Client Event Script. That way, you can monitor any tag you want (So you don’t have to change anything there), and you can have it monitor multiple tags at once.
Well the good news is that this is all already located in that very spot! The bad news is, is that I now have no clue what’s wrong, haha. Looks like I’ll have to be looking for spelling mistakes or something
It is Python slice syntax. The path variable holds a string. He is getting part of the string.
The syntax is: path[startPosition:endPosition]
That syntax means return part of the string between startPosition and endPosition.
The len() function returns the length of a string.
So the code is saying:
Return part of the string starting at the length of the string minus 5 and ending at the length of the string minus 4.
So if his string was, “8Line” then his code would specifically mean:
The length of the string is 5. So the starting position is 5 - 5, which equals 0. So the starting position is 0 which is the beginning of the string. The end position is 5 - 4, which equals 1. So the code returns the first character in the string which is “8”.
The best way to get familiar with the Python slice syntax is to practice using it. Make some Python strings, print them out to the console, make some slices and print them out, make changes and print it out again to see how the changes affect things.
Ok, that also is something good to know for future uses. For whatever reason though, my popup window is still not popping up when the value changes to 1. I’m not sure what else could be wrong with it
So I have no idea what was different about your script, other than the print commands, but it works now! I’m not sure if I just needed to restart my gateway or what, but that did it. So I’m not sure why it’s working now, but it is working!