如何将模型面板添加到maya PySide

时间:2017-05-16 10:12:53

标签: python pyside maya

我正在创建一个脚本,我想在QtDesigner中创建的grig布局中放置一个模型面板。

enter image description here

模型面板必须放在红色区域。我试过了

cmds.setParent(self.LAY_grid_modelEditor)
cmds.modelPanel('testEditor', cam='persp')
cmds.setParent('..')

但收到错误

  

RuntimeError:setParent:Object''没找到。

我在Maya 2015中使用PySide。

任何帮助......

1 个答案:

答案 0 :(得分:1)

这段代码实际上是我从http://nathanhorne.com/embedding-a-maya-widget-into-a-pyqt-ui/获取的,它将显示如何在pyqt中嵌入maya gui。这个方法也可以用于pyside。我修改了这个示例代码,现在它将加载一个modelPane

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.QMainWindow):
    def __init__(self, parent=getMayaWindow()):
        super(MayaSubWindow, self).__init__(parent)
        self.modelPne = cmds.modelPanel('testEditor', cam='persp')
        qtObj = toQtObject(self.modelPne)
        self.setCentralWidget(qtObj)

myWindow = MayaSubWindow()
myWindow.show()