我想将图形编辑器中显示曲线和曲线名称的部分添加到我已制作的菜单中。有没有人对我如何做到这一点有任何建议?
我试图获得与上图相似的内容。 添加图形和大纲。 我设法找到了大纲的代码(cmds.outlinerPanel),但我对图表不太确定:\
我正在使用maya 2014。
答案 0 :(得分:3)
好。使用Maya cmds创建图编辑器面板的超快速示例:
import maya.cmds as cmds
cmds.window()
cmds.frameLayout()
cmds.animCurveEditor()
cmds.showWindow()
但是,将来,如果你想添加任何不能作为Maya命令使用的Maya小部件,你可以使用PySide的强大功能来做到这一点。这是一个例子。这是我在Nathan Horne在embedding Maya UI widgets on Qt UI和PySide/Shiboken上的精彩帖子中略微修改过的代码:
import maya.cmds as cmds
import maya.OpenMayaUI as apiUI
from PySide import QtCore, QtGui
import shiboken
def wrapinstance(ptr, base=None):
"""
Utility to convert a pointer to a Qt class instance (PySide/PyQt compatible)
:param ptr: Pointer to QObject in memory
:type ptr: long or Swig instance
:param base: (Optional) Base class to wrap with (Defaults to QObject, which should handle anything)
:type base: QtGui.QWidget
:return: QWidget or subclass instance
:rtype: QtGui.QWidget
"""
if not globals().has_key('QtCore') or not globals().has_key('QtGui'):
return None
if ptr is None:
return None
ptr = long(ptr) # Ensure type
if globals().has_key('shiboken'):
if base is None:
qObj = shiboken.wrapInstance(long(ptr), QtCore.QObject)
metaObj = qObj.metaObject()
cls = metaObj.className()
superCls = metaObj.superClass().className()
if hasattr(QtGui, cls):
base = getattr(QtGui, cls)
elif hasattr(QtGui, superCls):
base = getattr(QtGui, superCls)
else:
base = QtGui.QWidget
return shiboken.wrapInstance(long(ptr), base)
elif globals().has_key('sip'):
base = QtCore.QObject
return sip.wrapinstance(long(ptr), base)
else:
return None
def getMayaWindow():
ptr = apiUI.MQtUtil.mainWindow()
return 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 wrapinstance(long(ptr), QtCore.QObject)
class MayaSubWindow(QtGui.QMainWindow):
def __init__(self, parent=getMayaWindow()):
super(MayaSubWindow, self).__init__(parent)
qtObj = toQtObject(cmds.animCurveEditor())
#Fill the window, could use qtObj.setParent
#and then add it to a layout.
self.setCentralWidget(qtObj)
myWindow = MayaSubWindow()
myWindow.show()
即使这是一段看似很长的代码,您也可以安全地将wrapinstance()
,getMayaWindow()
和toQtObject()
添加到您的实用程序模块中以供重复使用。
希望这很有用。