Reading the names of open windows

I need to check the names of the currently open windows in a client before opening a new window, so that I can return to the original windows when done.

I tried to use system.gui.getOpenedWindows(), but the name property of each window object doesn’t return the full window path, it only returns the name and misses out the names of folders the window is in.

The system.gui.getWindowNames() function does return the full path, but despite the help file saying Returns a list of the currently open window names sorted actually returns the names of every window in the project, open or not.

Is there any way of returning a list of open windows including their full path?

The function system.gui.getOpenedWindows() returns window handles, which can be used by the system.nav.openWindow() and system.nav.closeWindow() functions. If you are returning to those windows in the same script this should be sufficient, but there isn’t a good way to store window handles otherwise. Do you need this so you can return after the operator does something else?

Yes, the operator will be switching out to another window and needs to be able to return to where he started.

Unfortunately this doesn’t currently exist in a system function. I’ll put in a feature request, but in the mean time you can use this code as a workaround.

#get all the window names names = system.gui.getWindowNames() #empty list to be filled with open window names header = ["name"] windowList = [] #loop through the names for name in names: try: #check if the window is open. this throws a ValueError if not system.gui.getWindow(name) #append the name (this only executes if there was no error) windowList.append([name]) except ValueError: #the window wasn't open, do nothing pass #put the completed list of names into a property on this button = system.dataset.toDataSet(header, windowList)
This code will store the paths of the currently open windows to a dataset property on the button pressed.

Thanks for this workaround, Bobby. I’ll be able to easily adapt it to do what I want.