Finding Components on Other Windows


Learn how to grab information from components on any open window from a component's event script.

Video recorded using: Ignition 8.1


(open in window)

[00:00] In this video, we're going to cover how to write vision components scripts that can access the properties from components found in other windows. This is particularly useful because you can not bind a components property directly to component properties in other windows. Here, I have a window named window1. I'll go ahead and place a button on it like so. I will then create a new window, let's call it window2. I will place a basic text field component here and with my designer in preview mode, I will type some texts into it. Our goal is to get the button in window1 to read the text from this text field here in window2. The first thing we have to do is grab the window2 object from our button in window1. Let's see what this is going to look like. First, we head to the buttons action performed script handler. And on the script editor, I will use a system function to obtain window2. There are actually a few ways to go about this depending on your application's requirements. But the most direct way is to use the system.gui.getWindow system function. So, I will call my function and assign as returning object to a variable named window. Let's print the variable window and see what we get. Putting the designer in preview mode, I can press my button and I see that my window2 object gets printed out. This is because window2 is open. If I were to close it like so and press my button once more, we will get a value error telling us that window2 is not open. So how do we get around this? For this example, I will simply use Python's exception handling. So we say try to get window2 and print it's window object. Then we cache the value error exception. And in the event of value error exception is thrown, we can just print out to the console a message that says hey, window2 is not open. We can try it out once more. Yap, this is a lot nicer than the ugly error we saw before. Now, I will open window2 back up to continue our example. We have correctly obtained our window2 object from our button in window1. We have also handled the event where window2 is not open. Now, we must configure a script to drill down our window2 object and grab the text fields text property. One thing to realize is that when you get the window object itself, the first thing you need to do to start walking down into the component hierarchy is grab the root container. And that's done simply by accessing the windows root container property. So we can just say window.rootContainer. Then, we have to grab our text field component from the container. So we'll use to get component function passing in our text fields name, which happens to be text field. Finally, once we have drilled down to our text field component, we can simply access its text property by ".text" like this. Let's go ahead and give our console a break from printing and put this text in a message box. I will go system.gui.messageBox. I will pass it in my text fields text property as the first argument and then pass in a title for my message box as the second argument. I will press my button once more in preview mode and I see my text fields text from window2, appear on my message box.

You are editing this transcript.

Make any corrections to improve this transcript. We'll review any changes before posting them.