# Open/close docked window for certain main windows

**URL:** <https://forum.inductiveautomation.com/t/open-close-docked-window-for-certain-main-windows/76612>\
**Category:** Ignition\
**Tags:** vision\
**Created:** [July 19, 2023, 8:35pm UTC](https://forum.inductiveautomation.com/t/open-close-docked-window-for-certain-main-windows/76612 "2023-07-19T20:35:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yurie\_Han](https://avatars.discourse-cdn.com/v4/letter/y/8c91f0/32.png) [@Yurie\_Han](https://forum.inductiveautomation.com/u/Yurie_Han)\
**Post date:** [July 19, 2023, 8:35pm UTC](https://forum.inductiveautomation.com/t/open-close-docked-window-for-certain-main-windows/76612/1 "2023-07-19T20:35:28Z")

</div>

I have a docked window that is only for certain main windows (Main Window 1,2, and 3). On startup, Vision Client opens up to Main Window 1 with the docked window. I want to close the docked window when the user opens a different window of Vision Client, or none of the main windows of interest are open. However, even when another main window is open, the docked window remains. Therefore, I added this component scripting under the docked window's visionWindowOpened.

```auto
main_window_names = ["Main Window 1",
					"Main Window 2",
					"Main Windows 3",

def are_main_windows_open():
	for window_name in main_window_names:
		window = system.gui.getWindow(window_name)
		if window is None:
			return False
	return True
	
def close_docked_if_needed():
	docked_window = system.gui.getWindow("Docked Window")
	if docked_window is not None:
		if not are_main_windows_open():
			docked_window.close()

close_docked_if_needed()

```

However, I'm getting a ValueError that "Main Window 2 is not currently open." I'm not sure if my code is incorrect or if I shouldn't script this under the docked window's event handler.

---

<div class="post-metadata">

**Author:** ![Melvin\_Miclat](https://avatars.discourse-cdn.com/v4/letter/m/ba9def/32.png) [@Melvin\_Miclat](https://forum.inductiveautomation.com/u/Melvin_Miclat)\
**Post date:** [July 19, 2024, 7:50pm UTC](https://forum.inductiveautomation.com/t/open-close-docked-window-for-certain-main-windows/76612/2 "2024-07-19T19:50:33Z")

</div>

Is there anybody that can help on this?

---

<div class="post-metadata">

**Author:** ![Samuel\_Sueur](https://avatars.discourse-cdn.com/v4/letter/s/e36b37/32.png) [@Samuel\_Sueur](https://forum.inductiveautomation.com/u/Samuel_Sueur)\
**Post date:** [July 19, 2024, 8:12pm UTC](https://forum.inductiveautomation.com/t/open-close-docked-window-for-certain-main-windows/76612/3 "2024-07-19T20:12:36Z")

</div>

Can't fully answer the main topic, but you're getting a "ValueError" because you are trying to get a window that is not opened.

As a workaround, consider catching the error by doing the below (this comes straight from Ignition's documentation) :

```python
# This example will get the window named 'Overview' and then close it.
  
try:
   window = system.gui.getWindow('Overview')
   system.gui.closeWindow(window)
  
except ValueError:
   system.gui.warningBox("The Overview window isn't open")

```

Instead of the `system.gui.warningBox` in the `except`, consider using `pass` if you do not want to do anything with the error.

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [July 20, 2024, 6:22am UTC](https://forum.inductiveautomation.com/t/open-close-docked-window-for-certain-main-windows/76612/4 "2024-07-20T06:22:27Z")

</div>

Additionally, the `try/except` with gui locking popup could be avoided by qualifying the action in this way:

```python
# If the overview window is open, close it
if 'Overview' in system.gui.getOpenedWindowNames():
	window = system.gui.getWindow('Overview')
	system.gui.closeWindow(window)

```
