For readability.

import maya.OpenMayaUI as apiUIfrom PyQt4 import QtGui, QtCoreimport sip
def getMayaWindow():
    ptr = apiUI.MQtUtil.mainWindow()
    return sip.wrapinstance(long(ptr), QtCore.QObject)
def toQtObject(mayaName):
    '''
    Given the name of a Maya UI element of any type,
    return the corresponding QWidget or QAction.
    If the object does not exist, returns None
    '''
    ptr = apiUI.MQtUtil.findControl(mayaName)
    if ptr is None:
        ptr = apiUI.MQtUtil.findLayout(mayaName)
    if ptr is None:
        ptr = apiUI.MQtUtil.findMenuItem(mayaName)
    if ptr is not None:
        return sip.wrapinstance(long(ptr), QtCore.QObject)
class MayaSubWindow(QtGui.QDialog):
    def __init__(self, parent=None):
        super(MayaSubWindow, self).__init__(parent)

        self.setModal(True)

        self.verticalLayout = QtGui.QVBoxLayout(self)
        self.verticalLayout.setContentsMargins(0,0,0,0)
        self.verticalLayout.setMargin(0)
        self.verticalLayout.setSpacing(0)

        self.setLayout(self.verticalLayout)

        if cmds.modelEditor('snapEditor', query=True, exists=True):
          cmds.deleteUI('snapEditor', editor=True )
        self.mp = cmds.modelEditor('snapEditor',
displayAppearance='smoothShaded', selectionHiliteDisplay=False,
displayTextures=True, wos=False, camera='persp', imagePlane=False,
nurbsCurves=False, lights=False, cameras=False, grid=False,
joints=False, locators=False, headsUpDisplay=False)
        self.mp_qtObj = toQtObject(self.mp)

        self.verticalLayout.addWidget(self.mp_qtObj)
def getSnapshot():
    win = getMayaWindow()

    cs = MayaSubWindow(win)
    cs.show()
    cs.update()
    valid = cs.exec_()

    cs.close()

getSnapshot()

​

On 22 October 2014 06:48, zoshua <[email protected]> wrote:

> First time it runs fine.
> Succesive calls to getSnapshot() makes maya unstable.
> ..
> Anyone happen to get something like this working?
>
> ######################################
> import maya.OpenMayaUI as apiUI
> from PyQt4 import QtGui, QtCore
> import sip
>
> def getMayaWindow():
>     ptr = apiUI.MQtUtil.mainWindow()
>     return sip.wrapinstance(long(ptr), QtCore.QObject)
>
> def toQtObject(mayaName):
>     '''
>     Given the name of a Maya UI element of any type,
>     return the corresponding QWidget or QAction.
>     If the object does not exist, returns None
>     '''
>     ptr = apiUI.MQtUtil.findControl(mayaName)
>     if ptr is None:
>         ptr = apiUI.MQtUtil.findLayout(mayaName)
>     if ptr is None:
>         ptr = apiUI.MQtUtil.findMenuItem(mayaName)
>     if ptr is not None:
>         return sip.wrapinstance(long(ptr), QtCore.QObject)
>
> class MayaSubWindow(QtGui.QDialog):
>     def __init__(self, parent=None):
>         super(MayaSubWindow, self).__init__(parent)
>
>         self.setModal(True)
>
>         self.verticalLayout = QtGui.QVBoxLayout(self)
>         self.verticalLayout.setContentsMargins(0,0,0,0)
>         self.verticalLayout.setMargin(0)
>         self.verticalLayout.setSpacing(0)
>
>         self.setLayout(self.verticalLayout)
>
>         if cmds.modelEditor('snapEditor', query=True, exists=True):
>           cmds.deleteUI('snapEditor', editor=True )
>         self.mp = cmds.modelEditor('snapEditor',
> displayAppearance='smoothShaded', selectionHiliteDisplay=False,
> displayTextures=True, wos=False, camera='persp', imagePlane=False,
> nurbsCurves=False, lights=False, cameras=False, grid=False, joints=False,
> locators=False, headsUpDisplay=False)
>         self.mp_qtObj = toQtObject(self.mp)
>
>         self.verticalLayout.addWidget(self.mp_qtObj)
>
> def getSnapshot():
>     win = getMayaWindow()
>
>     cs = MayaSubWindow(win)
>     cs.show()
>     cs.update()
>     valid = cs.exec_()
>
>     cs.close()
>
> getSnapshot()
> ######################################
>
> --
> You received this message because you are subscribed to the Google Groups
> "Python Programming for Autodesk Maya" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/f8a09ce6-69de-43ce-9122-4dc3a1b4ae58%40googlegroups.com
> <https://groups.google.com/d/msgid/python_inside_maya/f8a09ce6-69de-43ce-9122-4dc3a1b4ae58%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
*Marcus Ottosson*
[email protected]

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOBz8_%3DFgDa761iq06gPbv1BFb%3DgQVoVFJCYS-WS%2BT7qYw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to