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)
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.
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():
systme.tag.writeBlocking('[default]LED',event.newValue)
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
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:
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
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
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: