Property change scripting

Hi, Im having trouble with my scripting for the visibility of a component.
I am new to ignition and just a beginner on scripting so any advice would be great!

My goal is to make the alarm status table on my docked window to become visible = false, when a certain “Alarms” window is the current main window viewed (or the root container of it is visible).
Currently I have tried the following statement on property change of the component, but I keep getting an error:

#To get other window's visibility property
AlarmWin = system.gui.getWindow("Alarm")
if ({AlarmWin.rootContainer.visible}) == true:
#if statement conditions the visibility of the component
        AlarmDock = system.gui.getwindow("Footer")
{AlarmDock.rootContainer.getComponent("Alarm Status Table").visible} = false

The error is when I run vision on this project saying that there is an error running this script, hence the visibility is not affected.

Please and thank you!

Few things:

  1. Edit your post to include code formatting markers instead the “quote” block. Should look like this in your editor:
    ```
    Pasted Code
    ```
    Yes, those are reverse single quotes, three at a time, above and below your code.

  2. propertyChange events run for pretty much every property on that component. You must nest all code within some form of if event.propertyName == 'someProp': so that it only runs for the specific property you care about. Not Optional.

  3. We aren’t mind readers–we don’t know what error you are getting. Post it too, pasting it with formatting markers just like a code block.

1 Like

What Phil said.
Also, you can’t use {AlarmWin.rootContainer.visible}, you should have seen squiggly red lines beside that code in the editor to indicate this.

The code below fixes up your syntax errors, although I’m still not sure it’s the best way to go about doing what you’re trying to do. I’m also not sure which property you should be looking at, nor which component this script is running on

if event.propertyName == '<propery name>':
	AlarmWin = None
	try:
		AlarmWin = system.gui.getWindow('Alarm') # this will error if the window isn't found
	except:
		pass
	
	try:
		AlarmDock = system.gui.getwindow('Footer')
		AlarmDock.rootContainer.getComponent('Alarm Status Table').visible = (AlarmWin == None)
	except:
		pass # or do something
1 Like

Hi,
Thank you. I’ve changed the post. Sorry, being new to the forums I’m unaware of the formatting rules and such.

I basically have an ‘alarm status table’ component on a docked window that shows at all times. However, im trying to make that invisible when i have the main window (that has a larger size version of the ‘alarm status table’ component) on as the current window.
Apologies for being unclear. I’m running the script on the component on the docked window, so this will be relying on the main window component.

An easier approach might be simply to look at the tag that holds the window path to the currently opened main window:
[System]Client/User/CurrentWindow
and directly bind that to the visible property :slight_smile:
You could use the expression:
{[System]Client/User/CurrentWindow} != 'Alarm'

You should also have a look through that System folder to see what else there is in there that you can use for other things.

Hi Nick,
First of all, thank you for your efforts and advice giving me help on this. really appreciate it…

I’m still trying to get the hang of ignition so i’ll thank you for your patience in advance.

For that … are you proposing i write the script in scripting > gateway events > tag change scripts?

if so, how would i direct to the visible property of my component with it ? Pls & ty

No worries, we were all new once!

And nope, that was an expression, not a script. The expression language is used within component bindings. Python scripting is used on component (and other) event handlers, like the propertyChange event.

You should put that expression within the Alarm Dock window’s Alarm Status Table’s visible property’s Expression binding. Click on the chain link icon beside the visible property to open the bindings window. I’ll get a screenshot in a sec

1 Like

Aw genius!
Thank you! So many ways to do 1 thing, just takes experience and expertise to know how to do it the right way.

hmm I’ve jsut tried it, “{[System]Client/User/CurrentWindow} != ‘Alarm’” on the expressions of the visibility binding on the docked component. it still seems to show up even with the main window on alarm… would it have to be the path to the page of alarm or just the name of the window?
But no errors which is still a leap forward

It needs to be the full window path. Sorry, I assumed that ‘Alarm’ was the full path

Oops sorry I had the end property .Name to the the {[System]Client/User/CurrentWindow} and thats why it wasnt working. and now it works perfect. Thank you very much Nick, I owe you!

3 Likes