Tip: Getting the Maya main window

Instead of messing with shiboken/sip to get a pointer to the main window in Maya, use this snippet (which is pretty obvious once you see it):


from PySide import QtGui

maya_window = None

for w in QtGui.QApplication.topLevelWidgets():
    if w.objectName() == 'MayaWindow':
        maya_window = w

Cheers,
Max

Seems simple and neat enough. Let’s just hope that Autodesk doesn’t arbitrarily change the name between Maya versions.