This lesson is part of the Scripting in Ignition course. You can browse the rest of the lessons below.

LESSON LIST

Autoplay Off

Description

Learn how to use the system.nav.* functions to manipulate the windows inside a Vision client. Learn the difference between swapTo and swapWindow.

Video recorded using: Ignition 7.7

Transcript

(open in window)

[00:00] In this lesson we're going to look at the scripting functions available for manipulating vision windows and navigating between windows. So I've got a project set up here with three windows. I've got an orange window and a green window that are both main windows as well as a popup window. So let's look at a client to see how this project behaves. And then we'll take a look at the scripting behind it. So when we open up the project the startup window opens, the green window, and it's a main window, which just means that start maximized is equal to true. And if we hit this swap to green button we swap over to the green window, and you can see that we only have one window open, so swapping from orange to green not only opened green in orange's place but it closed the orange window. By contrast, when we open the popup window, we now have two windows open. So opening a popup window clearly doesn't close the green window, it just opens an additional window. And you can see that the popup window knows exactly who opened it. So if I go back to orange and open the popup the popup window will say opened by orange. And that's done by parameter passing. We'll see that when we look at the scripting. The popup window also has the ability to swap the main windows behind it. So you can see that this popup window can perform the swap, which is a different way of swapping than these buttons, and we'll see that in just a second. So let's switch back to the designer and take a look at how all of this works. So the first thing the swap buttons on the orange and green windows that swap to each other are very simple. They simply call system.nav.swapTo. So here I am on the orange window and my swap button just says swapTo Green Window. And on the green window it's just going to say swapTo the Orange Window. Now, swapping involves two windows. You have the window you're swapping from and this window you're swapping to. But you'll notice that this function only takes the window you're swapping to. It doesn't need the window you're swapping from. And the way that works is that ignition expects most projects to be configured in such a way that there's only ever one main window open at a time. The reason is that having multiple main windows open at once is really just a waste of resources. If you ever end up in a situation where you have more than one main window open. You can only see one at a time. So it's probably a mistake anyhow. So the swapTo takes advantage of the idea that there's only one main window open. So when you try to swap to another one it can detect what the maximized window is that it should be swapping from just by looking at the windows that are open. Contrast that to the popup windows version of swapping, where it has specific buttons for swapping from green to orange and orange to green. And these ones, instead of calling the swapTo function they call the swap window function, which is, does the same thing except that it explicitly takes the two windows to swap to and from. And this can be important for a number of reasons. You might have a docked north header window that's swapping out the main windows beneath it or you might have, you might be swapping popup windows, right? You might have set up maybe a wizard type of setup that has a number of popup windows that need to swap into each other and seem like a seamless sequence of windows. Because swapping isn't inherently something that only main windows should do. Any window can swap into another window. All swapping is is closing one window and opening another one in the same position that the first one was in. Now you'll also notice that this popup window has a label that says opened by. And when we swapped, I'm sorry, when we opened the popup window the opened by could tell which of the main windows had opened the popup. And the way that we achieve that is through parameter passing. And this is a really important concept for window navigation because it's very common to create a parameterized window where the same window is opened by many places throughout your project but different parameters are passed to that window so it can represent different items. And the way we do this, in this case I simply use the navigation builder, because I wasn't doing anything fancy enough to make me write the script by hand. But it's still interesting to see what the script looks like, but there's certainly nothing wrong with using the navigation builder. So you can see I just checked the pass parameters option and said that the parameter name OpenedBy is set to the value of Orange. And that parameter is defined simply as a root container property. Any of the properties on a root container are up for receiving parameters when a window is opened. And if you were to code this thing by hand, the way you do this is by simply passing an optional second argument to the open window function, so system.nav.openWindow, you can just pass it the path to a window and it'll just open up that window with no parameters. But optionally you can give it a Python dictionary where the keys of the dictionary are the names of root container, properties on the target window, and the values in the dictionary are the values you'd like to pass for those parameters. And in closing, I'd just like to mention that if you're ever trying to come up with some sort of fancy navigation system, you might want to take a look at all of the other functions available in the system.nav library. There's a number of options in there for getting the windows that are open. You can open additional instances, so those are copies of a window. So you can have multiple copies of any given window open at a time. You can implement some sort of back, forward, home navigation. There's a number of useful options in here.

You are editing this transcript.

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