Popup window Script

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?

Hi Alex,

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 :frowning: 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.

So I have two questions :slight_smile:

  1. How do I make the tag a client tag?
  2. How do I scope the code to the client?

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.

You can read a bit more about it here:

https://support.inductiveautomation.com/usermanuals/ignition/


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 :confused:

Heh. Actually, it’s looking up! :slight_smile:

Try this one:

value = event.currentValue.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)

Also, you can put some print statements in there, and monitor it through the Console (Ctrl-Shift-C)

That is what my code looks like and it is still not working :/ Is anything else supposed to be indented or anything like that?

Also, what does this line of code mean?

compNum = path[len(path)-5:len(path)-4]

i know it’s defining the variable compNum, but i don’t understand the syntax following it :question:

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.

Best,

OK, that makes a ton of sense! So if my ‘string’ is just a value 0, 1 or 2 on an HOA tag, my code would look something like this: ?

compNum = path[len(path)-1:len(path)-0]

Your code gets the last character in a string.

I would do it like this:

compNum = path[-1:]

That means get part of the string starting at the end minus one and get the rest of the string.

If your string only contains a number in it then there is no need to get part of it. You could do:
compNum = path

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

Put a few print statement in and see what the values are. They’ll show up in the console.

[code]value = event.currentValue.value
path = str(event.tagPath)
compNum = path[len(path)-5:len(path)-4]

print “value=”, value
print “path=”, path
print “compNum=”, compNum

if value == 1:
win = system.nav.openWindowInstance(“Popups/Compressor Status”, {“CompressorNumber” : compNum})
system.nav.centerWindow(win)[/code]

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. :scratch: So I’m not sure why it’s working now, but it is working! :thumb_right: