# Popup window Script

**URL:** <https://forum.inductiveautomation.com/t/popup-window-script/10318>\
**Category:** Ignition\
**Created:** [August 7, 2015, 1:19pm UTC](https://forum.inductiveautomation.com/t/popup-window-script/10318 "2015-08-07T13:19:12Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![alewayhar](https://avatars.discourse-cdn.com/v4/letter/a/ebca7d/32.png) [@alewayhar](https://forum.inductiveautomation.com/u/alewayhar)\
**Post date:** [August 7, 2015, 1:19pm UTC](https://forum.inductiveautomation.com/t/popup-window-script/10318/1 "2015-08-07T13:19:12Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [August 7, 2015, 5:25pm UTC](https://forum.inductiveautomation.com/t/popup-window-script/10318/2 "2015-08-07T17:25:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![alewayhar](https://avatars.discourse-cdn.com/v4/letter/a/ebca7d/32.png) [@alewayhar](https://forum.inductiveautomation.com/u/alewayhar)\
**Post date:** [August 7, 2015, 7:14pm UTC](https://forum.inductiveautomation.com/t/popup-window-script/10318/3 "2015-08-07T19:14:38Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [August 7, 2015, 7:19pm UTC](https://forum.inductiveautomation.com/t/popup-window-script/10318/4 "2015-08-07T19:19:15Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![alewayhar](https://avatars.discourse-cdn.com/v4/letter/a/ebca7d/32.png) [@alewayhar](https://forum.inductiveautomation.com/u/alewayhar)\
**Post date:** [August 7, 2015, 7:33pm UTC](https://forum.inductiveautomation.com/t/popup-window-script/10318/5 "2015-08-07T19:33:23Z")

</div>

So I have two questions 🙂

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

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [August 7, 2015, 7:45pm UTC](https://forum.inductiveautomation.com/t/popup-window-script/10318/6 "2015-08-07T19:45:12Z")

</div>

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/](https://support.inductiveautomation.com/usermanuals/ignition/)

 ![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/8/84889b0b9e9b6ea133911b73d2ac649045835d0d.jpg)

---

<div class="post-metadata">

**Author:** ![alewayhar](https://avatars.discourse-cdn.com/v4/letter/a/ebca7d/32.png) [@alewayhar](https://forum.inductiveautomation.com/u/alewayhar)\
**Post date:** [August 7, 2015, 7:52pm UTC](https://forum.inductiveautomation.com/t/popup-window-script/10318/7 "2015-08-07T19:52:31Z")

</div>

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 😕

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [August 7, 2015, 8:37pm UTC](https://forum.inductiveautomation.com/t/popup-window-script/10318/8 "2015-08-07T20:37:53Z")

</div>

Heh. Actually, it’s looking up! 🙂

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)

---

<div class="post-metadata">

**Author:** ![alewayhar](https://avatars.discourse-cdn.com/v4/letter/a/ebca7d/32.png) [@alewayhar](https://forum.inductiveautomation.com/u/alewayhar)\
**Post date:** [August 10, 2015, 2:30pm UTC](https://forum.inductiveautomation.com/t/popup-window-script/10318/9 "2015-08-10T14:30:33Z")

</div>

That is what my code looks like and it is still not working ![:/](https://us1.discourse-cdn.com/inductiveautomation/original/1X/8e510869ae26fbd7ab76e1e731ceea2054ef109c.gif "Hrm") Is anything else supposed to be indented or anything like that?

---

<div class="post-metadata">

**Author:** ![alewayhar](https://avatars.discourse-cdn.com/v4/letter/a/ebca7d/32.png) [@alewayhar](https://forum.inductiveautomation.com/u/alewayhar)\
**Post date:** [August 10, 2015, 2:34pm UTC](https://forum.inductiveautomation.com/t/popup-window-script/10318/10 "2015-08-10T14:34:47Z")

</div>

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 ❓

---

<div class="post-metadata">

**Author:** ![nmudge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nmudge/32/3394_2.png) [@nmudge](https://forum.inductiveautomation.com/u/nmudge)\
**Post date:** [August 10, 2015, 3:04pm UTC](https://forum.inductiveautomation.com/t/popup-window-script/10318/11 "2015-08-10T15:04:35Z")

</div>

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,

---

<div class="post-metadata">

**Author:** ![alewayhar](https://avatars.discourse-cdn.com/v4/letter/a/ebca7d/32.png) [@alewayhar](https://forum.inductiveautomation.com/u/alewayhar)\
**Post date:** [August 10, 2015, 3:18pm UTC](https://forum.inductiveautomation.com/t/popup-window-script/10318/12 "2015-08-10T15:18:42Z")

</div>

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]

---

<div class="post-metadata">

**Author:** ![nmudge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nmudge/32/3394_2.png) [@nmudge](https://forum.inductiveautomation.com/u/nmudge)\
**Post date:** [August 10, 2015, 3:22pm UTC](https://forum.inductiveautomation.com/t/popup-window-script/10318/13 "2015-08-10T15:22:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![alewayhar](https://avatars.discourse-cdn.com/v4/letter/a/ebca7d/32.png) [@alewayhar](https://forum.inductiveautomation.com/u/alewayhar)\
**Post date:** [August 10, 2015, 3:33pm UTC](https://forum.inductiveautomation.com/t/popup-window-script/10318/14 "2015-08-10T15:33:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [August 10, 2015, 7:01pm UTC](https://forum.inductiveautomation.com/t/popup-window-script/10318/15 "2015-08-10T19:01:52Z")

</div>

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]

---

<div class="post-metadata">

**Author:** ![alewayhar](https://avatars.discourse-cdn.com/v4/letter/a/ebca7d/32.png) [@alewayhar](https://forum.inductiveautomation.com/u/alewayhar)\
**Post date:** [August 10, 2015, 8:30pm UTC](https://forum.inductiveautomation.com/t/popup-window-script/10318/16 "2015-08-10T20:30:34Z")

</div>

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:](https://us1.discourse-cdn.com/inductiveautomation/original/1X/76d1620bec252bfac07050c889ff5a91dc8a9c25.gif ":scratch:") So I’m not sure why it’s working now, but it is working! ![:thumb_right:](https://us1.discourse-cdn.com/inductiveautomation/original/1X/2026e28c0c425034352c1b75807edf956adc75f4.gif ":thumb\_right:")
