1. from PySide2 import QtWidgets
  2. import maya.cmds as cmds
  3. window = QtWidgets.QWidget()
  4. window.resize(500,500)
  5. qtLayout = QtWidgets.QVBoxLayout(window)
  6. qtLayout.setObjectName('viewportLayout')
  7. cmds.setParent('viewportLayout')
  8. cmds.modelPanel("embeddedModelPanel#", cam='persp')
  9. window.show()
  1. from PySide2 import QtWidgets
  2. import maya.cmds as cmds
  3. import maya.OpenMayaUI as mui
  4. import shiboken2
  5. # We create a simple window with a QWidget
  6. window = QtWidgets.QWidget()
  7. window.resize(500,500)
  8. # We have our Qt Layout where we want to insert, say, a Maya viewport
  9. qtLayout = QtWidgets.QVBoxLayout(window)
  10. # We set a qt object name for this layout.
  11. qtLayout.setObjectName('viewportLayout')
  12. # We set the given layout as parent to carry on creating Maya UI using Maya.cmds and create the paneLayout under it.
  13. cmds.setParent('viewportLayout')
  14. paneLayoutName = cmds.paneLayout()
  15. # Create the model panel. I use # to generate a new panel with no conflicting name
  16. modelPanelName = cmds.modelPanel("embeddedModelPanel#", cam='persp')
  17. # Find a pointer to the paneLayout that we just created using Maya API
  18. ptr = mui.MQtUtil.findControl(paneLayoutName)
  19. # Wrap the pointer into a python QObject. Note that with PyQt QObject is needed. In Shiboken we use QWidget.
  20. paneLayoutQt = shiboken2.wrapInstance(long(ptr), QtWidgets.QWidget)
  21. # Now that we have a QtWidget, we add it to our Qt layout
  22. qtLayout.addWidget(paneLayoutQt)
  23. window.show()
文档更新时间: 2018-06-18 06:29   作者:刘电