Switching windows with a button based on which window is open

New Ignition user here. So far all my questions have been answered on these forums as asked by other people or in the Inductive Automation University. However I do not seem to be able to find an answer to the question I have involving navigation with buttons between factory lines 1 and 2.

I have a docked window on the bottom of the screen that has buttons that go to different windows. (I.e. a button labeled “Misc. Utilities” goes to the window “Util System” and shows utilities related information. The button labeled “Cooling Water” goes to the window “CW System” and shows things related to that.) So far so good and all makes sense and works.

The problem comes into being with buttons such as “Feed System.” I can make it go to “FeedSys_PO1” window just fine. Same with the “Melting CRF” button, it goes to the window “MELT1” with no issues. The problem is that I need to be able to go to “FeedSys_PO2” if “FeedSys PO1” is open, or to "MELT2 " if “MELT1” is open, and vice versa.

I thought that creating a separate button on the docked window at the bottom of the screen that would switch between “MELT1 System” and “MELT2 System” or “FeedSys PO1” and “FeedSys PO2” would work. Something simple along the lines of

If window == ‘Main Windows/FeedSys_PO1’
then system.nav.openWindow ‘Main Windows/FeedSys_PO2’
If window == ‘Main Window/FeedSys_PO2’
then system.nav.openWindow ‘Main Windows/FeedSys_PO1’

However I do not seem to know how to code this so that it works or I am missing something that would make this easier/work. Any help would be greatly appreciated. I do have my windows separated into the folders “Main Windows” and “Popups” so all the windows I am trying to switch between/open are in the Main Windows folder as shown in the attempted code above this.

You need to get the path of the window that is open.

In your buttons actionPerformed Script do this:

win = system.gui.getParentWindow(event).path

if win == 'Main Windows/FeedSys_PO1':
	system.nav.swapTo('Main Windows/FeedSys_PO2')
elif win == 'Main Windows/FeedSys_PO2':
	system.nav.swapTo('Main Windows/FeedSys_PO1')

I would recommend that take a look at the differences between the navigation functions.

Specifically system.nav.swapTo and system.nav.openWindow. Most of the time, in my experience, swapTo is the way to go.

@lrose
That makes Ignition happier, thank you.

However, it does not seem to work. I am wondering if the
“win = system.gui.getParentWindow(event).path”
is reading the window that the buttons are on and not the main window. The window the buttons are on at the bottom of the screen does not change (it is docked, or should be.) The windows above it are the ones that change. Anyone have any thoughts?

Yeah, that would definitely change things.

Depending on how many windows you have opened at once, then you may want to take a slightly different approach.

On your docked window's root container with the navigation buttons, create a custom property to hold the path of the main window, perhaps mainPath. Then after each navigation update the property so that it holds the path of the current main window.

Then you can use that property in your check.

You will also want to change from swapTo to swapWindow

Something like:

win = event.parent.mainPath

if win == 'Main Windows/FeedSys_PO1':
	system.nav.swapWindow(win,'Main Windows/FeedSys_PO2')
    event.parent.mainPath = 'Main Windows/FeedSys_PO2'
elif win == 'Main Windows/FeedSys_PO2':
	system.nav.swapWindow(win,'Main Windows/FeedSys_PO1')
    event.parent.mainPath = 'Main Windows/FeedSys_PO1'

Thank you.
Sadly though, I am unable to figure out on my own how to get a custom property on a window’s root container to hold a custom “mainPath” property of the current path of the main window. Nor can I figure out how to get that property to update on each navigation. (Property change scripting?)

No worries.

In the project browser, select the Root Container of the window, right click and Custom Properties from the Customizers.

image

This will open the Custom Properties popup. Click on the + to add a custom property, give the property a name and change the type to string.

image

Then click the OK button. Now this property will be accessible just like any other property of the root container. Anytime you navigate to a new screen, write the new path to the property.

event.parent.mainPath = 'Path of the window being navigated to'

Sorry I did not get back to this yesterday. I am very appreciative of the help you are giving me @lrose.
I am back to working on this now though.

I was able to figure out how to create the Custom Property and give it a name and make it a String. What I am not understanding currently is how and where to write the path of the window being navigated to or that is currently displayed.

Anytime you navigate to a new screen you will write to the property.

You can accomplish this in the actionPerformed script.

system.nav.swapWindow(win,'Main Windows/FeedSys_PO2')

#This  line writes the path to the main path property
event.parent.mainPath = 'Main Windows/FeedSys_PO2'