Is it possible to hide and restore windows in Maya?

Does Maya offer any support for restoring open windows after they have been closed?

What I am trying to do is create a “clean” save that does have any open windows, but I do not want to disturb the artist workflow by saving off an entirely different scene and then reverting back to the original (and taking a lot of loading time), or by destroying all their open windows when they click save.

I was hoping that setting the windows visible attribute to False and then switching it back to True would give me this result, but Maya destroys the window once it’s visibility is set to False.

For example, the code below would hopefully just quickly toggle the visibility of the window, but once it is set visible=False it is gone for good.

Is there another way to store the current windows that are open in Maya and retrieve that state again?

import maya.cmds as cmds
def get_user_windows():
    '''
    Get the non-builtin windows as a list.
    '''
    all_windows = cmds.lsUI(windows=True)
    builtin_windows = ["ColorEditor", 
                       "CommandWindow", 
                       "MayaWindow", 
                       "scriptEditorPanel1Window"]
    
    return [w for w in all_windows if w not in builtin_windows]

user_windows = get_user_windows()

for user_window in user_windows:
    cmds.window(user_window, edit=True, visible=False)
    
# Running this immediately and the window does not turn visible
# Running this after an idle cycle and you get runtime error "Object not found"
for user_window in user_windows:
    cmds.window(user_window, edit=True, visible=True)

You don’t say what version of Maya you are using, but if it is 2012, then you should be able to use PyQT to talk to the window directly and hide it “without Maya knowing”.

See saveState and restoreState in:
http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qmainwindow.html
This inherits from QWidget. I believe you want setVisible:

http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qwidget.html
http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qwidget.html#setVisible

and as always, take a look at Nathan Horne’s excellent blog:

http://nathanhorne.com/

He has examples of how to get the handle for Maya windows in PyQT.

Using Qt you can try to make dock window like channel box, so you can hide n show window whenever you want, i show this in autodesk 2011 master class.

I suspect the cmds.window with visible=False will destroy the window object. I wonder what would happen if you just used Qt to hide it? .setVisible(bool) (or setHidden/setShowing, or something). Note sure that’d work/actually save it.

Thanks for the all the replies, yes I am using Maya 2012 (Hotfix 4 x64). I will certainly give the Qt approach a try. I don’t really want to dock the windows (since they will still be loaded), but that is another approach.

Baring any success I will go down the path of grabbing the uiConfigurationNode and parsing out some of the data from that (which won’t be pretty).