Finding Components on Other Windows

In Ignition, you can obtain and use information from components on other windows. To access the information, first you need to know the window name, component name, and the property that you want to obtain. In addition, if the window is not open an error will occur. This error can be handled with normal exception handling.

The following example demonstrates how to access the contents of a text field on a different window from where the scripting occurred.

try:
window = system.gui.getWindow("Other Window")
text = window.rootContainer.getComponent("Text Field").text
print text
except ValueError:
print "Other window is not open"

Sometimes you may want to reference components on other windows. Or maybe you don't have an 'event' object because you're writing a project event script. In this case, you'll need to look up the containing window first. You can do this with the system.gui.getWindow() function. This function will throw a ValueError if the given window isn't open, so you should make sure your code handles that gracefully. Once you have a Window, you can use its rootContainer property to get into the standard component hierarchy. This code will look up the HeaderLabel on a window named "Overview" and set its text and foreground color.

try:
window = system.gui.getWindow("Overview")
label = window.rootContainer.getComponent("HeaderLabel")
label.text = "Notice Me!"
label.foreground = (255,0,0)
except ValueError:
# ignore error with a pass keyword
pass