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)