Turn on a plc tag based on visibility of a component and the open/close state of a window

Hello everyone,

For an application, I am trying to light up an led based on the visibility of a tag and a screen.
So, I wrote this script on property change and when the tag is visible and the Top window is open I want the led to light up. However, the code is not working properly. I would appreciate any ideas or suggestions. Thank you!

if event.propertyName=="visible" and system.nav.getCurrentWindow()=="Top":
    system.tag.writeBlocking("[default]LED", event.source.visible)

Does your code really have double quotes before the system.nav. call?

No it does not, this was a typo when I wrote the code here.

Looks correct to me, as long as the complete path to the main window is “Top” :thinking:

Maybe do a:

print event.propertyName, system.nav.getCurrentWindow()

At the top and see what you get?


it says
text none
visible none

Is it correct to have both visibility and window name at the same time?
I can see the led lights up but when I change the screen to "Bottom" instead of "Top" nothing happens.

Does the "Top" window actually have focus?

Based only on the names you have given for your windows (e.g. "Top", "Bottom") these sound like perhaps docked windows or pop up windows.

From the description of getCurrentWindow() found here

Returns the path of the current "main screen" window, which is defined as the maximized window. With the typical navigation, there is only ever one maximized window at a time.

I can't really think of a time when getCurrentWindow() would return none

A better option might be to just check if the window is open, since it seems that is what you're actually concerned about.

if event.propertyName == 'visible' and 'Top' in system.gui.getOpenedWindowNames():
1 Like

Thank you very much for your reply.
‘Top’ and ‘bottom’ are two windows I have in vision (main windows). None of them are dock windows or pop ups.
I tried your code, but it does not work either. The led is open regardless of the opened screen.

I want to light up the led if I have a label visible on the screen and at the same time the Top window is open

What is the actual path of this window?

Are the windows set to show as maximised? Can you try reading the client tag that stores the current window and print that out?

1 Like

“Top” for top window and “Bottom” for bottom

maximizable property on both windows is off now. Should I turn them on?
no client tags store the current window. I want to know what is the best practice here:

And the question is how to light up the led (plc output) when we have two conditions in the ignition:

  1. a component is visible
  2. a specific window is open

For a Window to be classed as the “main window”, it needs to be set to start as maximised. Sounds like this is why the function is returning null

Also my apologies, it’s not a client tag that stores the main window, it’s a system tag under a Client folder: [System]Client/User/CurrentWindow

1 Like

So this means both windows have to be set as “start as maximised”, correct?
I am going to check the currentwindow. Thank you!!

Well, you should only ever have one main window open at a time, the others should be set as docked windows if they need to be open at the same time. The current Main Window, in the case that you ever have more than one open at once (which you shouldn’t), from memory will be the last main window that was opened.

Edit: Either set them as docked windows, or incorporate them into your main window

1 Like

When I launch the project I can see only one window is open at the time, and I am toggling between those windows using an OPT touch button.

What’s an OPT touch button?
Also, are you using Swap Window? If you’re using Open Window, then you’ll be opening multiple main windows at once which will cause havoc

1 Like

OPT touch button is a optical touch buttons which is a replacement for mechanical push buttons. It returns boolean tag and I am using that in my program to toggle the screens. I believe I am using swap, but I do not have the screen opened in front of me so I cannot tell for sure.

Ok, that doesn’t sound like an issue.
To summarise though, you need to check that all main windows (e.g. Top and Bot) all have Start Maximised checked, and also confirm that the Main Window is set to this (either in the System tag or using the system.nav function).

This is how a typical Main Window should be setup:

1 Like

I just checked and both of them are configured exactly like the picture you sent.

1 Like

Where are you triggering the script, does it trigger when you change views? Im not sure a property change event will always do that

1 Like