Discussion:
[Maya-Python] How to embed modelPanel to a pyqt ui (again) ?
n***@gmail.com
2017-09-15 19:31:21 UTC
Permalink
hello, and by the way have you found a solution for the |||| in the name when is a nested layout working as a parent ??
--
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 python_inside_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/aaec3587-1350-49fc-97a0-6b8e015b5518%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
AJ
2017-09-26 16:02:10 UTC
Permalink
+1
Post by n***@gmail.com
hello, and by the way have you found a solution for the |||| in the name
when is a nested layout working as a parent ??
--
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 python_inside_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/7d045d3a-5bd1-4b84-9285-f43641ff436c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Justin Israel
2017-09-26 18:23:14 UTC
Permalink
Post by n***@gmail.com
hello, and by the way have you found a solution for the |||| in the name
when is a nested layout working as a parent ??
As mentioned, you have to set object names for everything. And also avoid
adding a layout to a layout. You should put widgets between layouts :

Widget - layout - widget - layout
Post by n***@gmail.com
--
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
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/aaec3587-1350-49fc-97a0-6b8e015b5518%40googlegroups.com
.
For more options, visit https://groups.google.com/d/optout.
--
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 python_inside_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA3jXk-Dooco7E7JnZw2Vtjiw42WgnxhPcjsW4uK7Q58mg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
n***@gmail.com
2017-09-26 18:51:42 UTC
Permalink
Yes, after following many recomendations like yours, i found out that the sign " | " actually represent a layout without name in the route, so if you have something like G.Ex: my_window||||my_layout|etc|etc .. that means that you have 3 layouts without name, you have, why i said 3 and not 4 if there are 4 | between my_window and my_layout ? because we have to be aware that one of those " | " is the way how maya represents the hiererchy in paths, in my test, at least in mine, dont mind if we have nested layouts, or widgets in bettween, you just have to name all layouts that will represent the path to the viweport, not the widgets, in first i put a name on the widgets too, but just for testing after i deleted the object name from the widgets and leave it on the layouts and still work on ! thank you ! now everything will be ok !!
--
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 python_inside_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/fec09467-b065-4173-a525-7579f488d1cc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
tim2018
2018-08-17 16:14:56 UTC
Permalink
Hello, Thanks for the examples but I noticed that none of the icons in
modelEditorIconBar seem to work. Clicking on shaded or wireframe icons have
no effect in the viewport. Does anyone know how to fix this problem? I am
referring to example1.

Thanks
i know this has been asked
<https://groups.google.com/forum/#!topic/python_inside_maya/wioChE9IFDA>
on 2011 and Justine has an awesome example here
<https://gist.github.com/justinfx/1381489>
you saw the last few lines i commented out the setObjectName xxxx and
yyyyy, without them, when you run the code in maya, it successfully opens
the ui, but when you press 4 or 5 on the modelPanel, you will see the
updateModelPanelBar
MayaWindow|||formLayout1|viewPanes|modelPanel4|modelPanel5|modelPanel5;
notice the ||| part.
it seems as if without object names set, maya doesn't know how to find the
newly created modelPanel. also if i'm using mainwindow i also see this
error unless i set object names using an awkward workaround.
example1
from PyQt4 import QtCore,QtGui
import maya.cmds as cmds
import maya.OpenMayaUI as OpenMayaUI
import sip
windowPointer = OpenMayaUI.MQtUtil.mainWindow()
return sip.wrapinstance(long(windowPointer), QtCore.QObject)
super(MayaView,self).__init__(parent,**kwargs)
self.setObjectName('MyWindow')
self.setWindowTitle('3dView')
self.verticalLayout = QtGui.QVBoxLayout(self)
self.verticalLayout.setContentsMargins(0,0,0,0)
self.verticalLayout.setObjectName("mainLayout")
applyBut = QtGui.QPushButton('Apply')
closeBut = QtGui.QPushButton('Close')
butLayout = QtGui.QHBoxLayout()
butLayout.addWidget(applyBut)
butLayout.addWidget(closeBut)
butLayout.setObjectName("xxxBut")
layout = OpenMayaUI.MQtUtil.fullName(long(sip.unwrapinstance(self.
verticalLayout)))
print "vertical layout",layout
cmds.setParent(layout)
paneLayoutName = cmds.paneLayout()
# find a pointer to the paneLayout that we just created
ptr = OpenMayaUI.MQtUtil.findControl(paneLayoutName)
# warp the pointer into a python QObject
self.paneLayout = sip.wrapinstance(long(ptr),QtCore.QObject)
# new create a camera
self.cameraName = cmds.camera(n='PickerView_camera')[0]
cmds.hide(self.cameraName)
cmds.viewFit(self.cameraName,all=True)
self.modelPanelName = cmds.modelPanel(cam=self.cameraName,parent=
paneLayoutName)
# edit model panel
modelEditorValue = cmds.modelPanel(self.modelPanelName,q=True,me=
True)
cmds.modelEditor(modelEditorValue,e=True,da='smoothShaded',ca=
False,grid=False,hud=False,\
manipulators=False,displayTextures=True,ha=False,
j=False,ikh=False,df=False,\
dim=False,lc=False,nc=True,wos=False,dl='default'
,av=False)
# find a pointer to the modelPanel that we just created
ptr = OpenMayaUI.MQtUtil.findControl(self.modelPanelName)
#wrap the pointer into a python QObject
self.modelPanel = sip.wrapinstance(long(ptr),QtCore.QObject)
#add our QObject reference to the paneLayout to our layout
self.verticalLayout.addWidget(self.paneLayout)
self.verticalLayout.addLayout(butLayout)
self.verticalLayout.setSpacing(0)
self.setLayout(self.verticalLayout)
self.setFixedSize(400,600)
super(MainWin,self).__init__(parent)
cam = MayaView()
# self.setObjectName('xxxxxx')
but = QtGui.QPushButton('zzz')
layout = QtGui.QVBoxLayout()
layout.addWidget(but)
layout.addWidget(cam)
self.setLayout(layout)
# layout.setObjectName('yyyyy')
a = MainWin()
a.show()
from PyQt4 import QtCore,QtGui
import maya.cmds as cmds
import maya.OpenMayaUI as OpenMayaUI
import sip
windowPointer = OpenMayaUI.MQtUtil.mainWindow()
return sip.wrapinstance(long(windowPointer), QtCore.QObject)
super(MayaView,self).__init__(parent,**kwargs)
self.setObjectName('MyWindow')
self.setWindowTitle('3dView')
self.verticalLayout = QtGui.QVBoxLayout(self)
self.verticalLayout.setContentsMargins(0,0,0,0)
self.verticalLayout.setObjectName("mainLayout")
applyBut = QtGui.QPushButton('Apply')
closeBut = QtGui.QPushButton('Close')
butLayout = QtGui.QHBoxLayout()
butLayout.addWidget(applyBut)
butLayout.addWidget(closeBut)
layout = OpenMayaUI.MQtUtil.fullName(long(sip.unwrapinstance(self.
verticalLayout)))
cmds.setParent(layout)
paneLayoutName = cmds.paneLayout()
# find a pointer to the paneLayout that we just created
ptr = OpenMayaUI.MQtUtil.findControl(paneLayoutName)
# warp the pointer into a python QObject
self.paneLayout = sip.wrapinstance(long(ptr),QtCore.QObject)
# new create a camera
self.cameraName = cmds.camera(n='PickerView_camera')[0]
cmds.hide(self.cameraName)
cmds.viewFit(self.cameraName,all=True)
self.modelPanelName = cmds.modelPanel(cam=self.cameraName)
cmds.panel(self.modelPanelName,e=True,mbv=False)
flayout = cmds.modelPanel(self.modelPanelName,q=True,barLayout=
True)
cmds.frameLayout(flayout,e=True,collapse=True)
# edit model panel
modelEditorValue = cmds.modelPanel(self.modelPanelName,q=True,me=
True)
cmds.modelEditor(modelEditorValue,e=True,da='smoothShaded',ca=
False,grid=False,hud=False,\
manipulators=False,displayTextures=True,ha=False,
j=False,ikh=False,df=False,\
dim=False,lc=False,nc=True,wos=False,dl='default'
,av=False)
# find a pointer to the modelPanel that we just created
ptr = OpenMayaUI.MQtUtil.findControl(self.modelPanelName)
#wrap the pointer into a python QObject
self.modelPanel = sip.wrapinstance(long(ptr),QtCore.QObject)
#add our QObject reference to the paneLayout to our layout
self.verticalLayout.addWidget(self.paneLayout)
self.verticalLayout.addLayout(butLayout)
self.verticalLayout.setSpacing(0)
self.setLayout(self.verticalLayout)
self.setFixedSize(400,600)
super(MainWin,self).__init__(parent)
self.setObjectName('QtMainWindow')
self.mid = QtGui.QMdiArea()
self.mid.setObjectName('QMdiArea')
self.setCentralWidget(self.mid)
cam = MayaView()
self.mid.addSubWindow(cam)
a = MainWin()
a.show()
--
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 python_inside_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/dfa30f8a-617b-4e4b-8aac-f373054739db%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Justin Israel
2018-08-20 01:37:26 UTC
Permalink
Post by tim2018
Hello, Thanks for the examples but I noticed that none of the icons in
modelEditorIconBar seem to work. Clicking on shaded or wireframe icons have
no effect in the viewport. Does anyone know how to fix this problem? I am
referring to example1.
Thanks
I've updated the original blog post with a Maya >= 2017 port of that
example code:
http://justinfx.com/2011/11/20/mixing-pyqt4-widgets-and-maya-ui-objects/

I tested it in Maya 2018 and it seems like the toolbar icons in the model
editor worked just fine. Can you confirm?
Post by tim2018
i know this has been asked
<https://groups.google.com/forum/#!topic/python_inside_maya/wioChE9IFDA>
on 2011 and Justine has an awesome example here
<https://gist.github.com/justinfx/1381489>
you saw the last few lines i commented out the setObjectName xxxx and
yyyyy, without them, when you run the code in maya, it successfully opens
the ui, but when you press 4 or 5 on the modelPanel, you will see the
updateModelPanelBar
MayaWindow|||formLayout1|viewPanes|modelPanel4|modelPanel5|modelPanel5;
notice the ||| part.
it seems as if without object names set, maya doesn't know how to find
the newly created modelPanel. also if i'm using mainwindow i also see this
error unless i set object names using an awkward workaround.
example1
from PyQt4 import QtCore,QtGui
import maya.cmds as cmds
import maya.OpenMayaUI as OpenMayaUI
import sip
windowPointer = OpenMayaUI.MQtUtil.mainWindow()
return sip.wrapinstance(long(windowPointer), QtCore.QObject)
super(MayaView,self).__init__(parent,**kwargs)
self.setObjectName('MyWindow')
self.setWindowTitle('3dView')
self.verticalLayout = QtGui.QVBoxLayout(self)
self.verticalLayout.setContentsMargins(0,0,0,0)
self.verticalLayout.setObjectName("mainLayout")
applyBut = QtGui.QPushButton('Apply')
closeBut = QtGui.QPushButton('Close')
butLayout = QtGui.QHBoxLayout()
butLayout.addWidget(applyBut)
butLayout.addWidget(closeBut)
butLayout.setObjectName("xxxBut")
layout = OpenMayaUI.MQtUtil.fullName(long(sip.unwrapinstance(self
.verticalLayout)))
print "vertical layout",layout
cmds.setParent(layout)
paneLayoutName = cmds.paneLayout()
# find a pointer to the paneLayout that we just created
ptr = OpenMayaUI.MQtUtil.findControl(paneLayoutName)
# warp the pointer into a python QObject
self.paneLayout = sip.wrapinstance(long(ptr),QtCore.QObject)
# new create a camera
self.cameraName = cmds.camera(n='PickerView_camera')[0]
cmds.hide(self.cameraName)
cmds.viewFit(self.cameraName,all=True)
self.modelPanelName = cmds.modelPanel(cam=self.cameraName,parent=
paneLayoutName)
# edit model panel
modelEditorValue = cmds.modelPanel(self.modelPanelName,q=True,me=
True)
cmds.modelEditor(modelEditorValue,e=True,da='smoothShaded',ca=
False,grid=False,hud=False,\
manipulators=False,displayTextures=True,ha=False
,j=False,ikh=False,df=False,\
dim=False,lc=False,nc=True,wos=False,dl=
'default',av=False)
# find a pointer to the modelPanel that we just created
ptr = OpenMayaUI.MQtUtil.findControl(self.modelPanelName)
#wrap the pointer into a python QObject
self.modelPanel = sip.wrapinstance(long(ptr),QtCore.QObject)
#add our QObject reference to the paneLayout to our layout
self.verticalLayout.addWidget(self.paneLayout)
self.verticalLayout.addLayout(butLayout)
self.verticalLayout.setSpacing(0)
self.setLayout(self.verticalLayout)
self.setFixedSize(400,600)
super(MainWin,self).__init__(parent)
cam = MayaView()
# self.setObjectName('xxxxxx')
but = QtGui.QPushButton('zzz')
layout = QtGui.QVBoxLayout()
layout.addWidget(but)
layout.addWidget(cam)
self.setLayout(layout)
# layout.setObjectName('yyyyy')
a = MainWin()
a.show()
from PyQt4 import QtCore,QtGui
import maya.cmds as cmds
import maya.OpenMayaUI as OpenMayaUI
import sip
windowPointer = OpenMayaUI.MQtUtil.mainWindow()
return sip.wrapinstance(long(windowPointer), QtCore.QObject)
super(MayaView,self).__init__(parent,**kwargs)
self.setObjectName('MyWindow')
self.setWindowTitle('3dView')
self.verticalLayout = QtGui.QVBoxLayout(self)
self.verticalLayout.setContentsMargins(0,0,0,0)
self.verticalLayout.setObjectName("mainLayout")
applyBut = QtGui.QPushButton('Apply')
closeBut = QtGui.QPushButton('Close')
butLayout = QtGui.QHBoxLayout()
butLayout.addWidget(applyBut)
butLayout.addWidget(closeBut)
layout = OpenMayaUI.MQtUtil.fullName(long(sip.unwrapinstance(self
.verticalLayout)))
cmds.setParent(layout)
paneLayoutName = cmds.paneLayout()
# find a pointer to the paneLayout that we just created
ptr = OpenMayaUI.MQtUtil.findControl(paneLayoutName)
# warp the pointer into a python QObject
self.paneLayout = sip.wrapinstance(long(ptr),QtCore.QObject)
# new create a camera
self.cameraName = cmds.camera(n='PickerView_camera')[0]
cmds.hide(self.cameraName)
cmds.viewFit(self.cameraName,all=True)
self.modelPanelName = cmds.modelPanel(cam=self.cameraName)
cmds.panel(self.modelPanelName,e=True,mbv=False)
flayout = cmds.modelPanel(self.modelPanelName,q=True,barLayout=
True)
cmds.frameLayout(flayout,e=True,collapse=True)
# edit model panel
modelEditorValue = cmds.modelPanel(self.modelPanelName,q=True,me=
True)
cmds.modelEditor(modelEditorValue,e=True,da='smoothShaded',ca=
False,grid=False,hud=False,\
manipulators=False,displayTextures=True,ha=False
,j=False,ikh=False,df=False,\
dim=False,lc=False,nc=True,wos=False,dl=
'default',av=False)
# find a pointer to the modelPanel that we just created
ptr = OpenMayaUI.MQtUtil.findControl(self.modelPanelName)
#wrap the pointer into a python QObject
self.modelPanel = sip.wrapinstance(long(ptr),QtCore.QObject)
#add our QObject reference to the paneLayout to our layout
self.verticalLayout.addWidget(self.paneLayout)
self.verticalLayout.addLayout(butLayout)
self.verticalLayout.setSpacing(0)
self.setLayout(self.verticalLayout)
self.setFixedSize(400,600)
super(MainWin,self).__init__(parent)
self.setObjectName('QtMainWindow')
self.mid = QtGui.QMdiArea()
self.mid.setObjectName('QMdiArea')
self.setCentralWidget(self.mid)
cam = MayaView()
self.mid.addSubWindow(cam)
a = MainWin()
a.show()
--
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
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/dfa30f8a-617b-4e4b-8aac-f373054739db%40googlegroups.com
<https://groups.google.com/d/msgid/python_inside_maya/dfa30f8a-617b-4e4b-8aac-f373054739db%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
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 python_inside_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA16iJOC3rq-OviFM2zX6TzwUUmQWz184f-VEHnoBwZ9PA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Timothy Kim
2018-08-20 13:44:08 UTC
Permalink
Thank Justin. I don't have access to my code right now to check the differences between mine and this one but this code works perfectly fine. Thanks again.

________________________________
From: ***@googlegroups.com <***@googlegroups.com> on behalf of Justin Israel <***@gmail.com>
Sent: Sunday, August 19, 2018 9:37:26 PM
To: ***@googlegroups.com
Subject: Re: [Maya-Python] Re: How to embed modelPanel to a pyqt ui (again) ?

** Incoming mail from outside The Mill **



On Sat, Aug 18, 2018 at 4:14 AM tim2018 <***@themill.com<mailto:***@themill.com>> wrote:
Hello, Thanks for the examples but I noticed that none of the icons in modelEditorIconBar seem to work. Clicking on shaded or wireframe icons have no effect in the viewport. Does anyone know how to fix this problem? I am referring to example1.

Thanks

I've updated the original blog post with a Maya >= 2017 port of that example code:
http://justinfx.com/2011/11/20/mixing-pyqt4-widgets-and-maya-ui-objects/

I tested it in Maya 2018 and it seems like the toolbar icons in the model editor worked just fine. Can you confirm?



On Friday, 23 May 2014 13:50:56 UTC-4, oglop wrote:
i know this <http:///> has been asked<https://groups.google.com/forum/#!topic/python_inside_maya/wioChE9IFDA> on 2011 and Justine has an awesome example here<https://gist.github.com/justinfx/1381489>
you saw the last few lines i commented out the setObjectName xxxx and yyyyy, without them, when you run the code in maya, it successfully opens the ui, but when you press 4 or 5 on the modelPanel, you will see the following error message similar to :

updateModelPanelBar MayaWindow|||formLayout1|viewPanes|modelPanel4|modelPanel5|modelPanel5;

notice the ||| part.

it seems as if without object names set, maya doesn't know how to find the newly created modelPanel. also if i'm using mainwindow i also see this error unless i set object names using an awkward workaround.

example1

from PyQt4 import QtCore,QtGui

import maya.cmds as cmds
import maya.OpenMayaUI as OpenMayaUI
import sip

def getMayaWindow():
windowPointer = OpenMayaUI.MQtUtil.mainWindow()
return sip.wrapinstance(long(windowPointer), QtCore.QObject)

class MayaView(QtGui.QDialog):
def __init__(self,parent=None,**kwargs):
super(MayaView,self).__init__(parent,**kwargs)

self.setObjectName('MyWindow')

self.setWindowTitle('3dView')

self.verticalLayout = QtGui.QVBoxLayout(self)
self.verticalLayout.setContentsMargins(0,0,0,0)
self.verticalLayout.setObjectName("mainLayout")

applyBut = QtGui.QPushButton('Apply')
closeBut = QtGui.QPushButton('Close')
butLayout = QtGui.QHBoxLayout()
butLayout.addWidget(applyBut)
butLayout.addWidget(closeBut)
butLayout.setObjectName("xxxBut")

layout = OpenMayaUI.MQtUtil.fullName(long(sip.unwrapinstance(self.verticalLayout)))
print "vertical layout",layout

cmds.setParent(layout)

paneLayoutName = cmds.paneLayout()
# find a pointer to the paneLayout that we just created
ptr = OpenMayaUI.MQtUtil.findControl(paneLayoutName)
# warp the pointer into a python QObject
self.paneLayout = sip.wrapinstance(long(ptr),QtCore.QObject)

# new create a camera
self.cameraName = cmds.camera(n='PickerView_camera')[0]
cmds.hide(self.cameraName)
cmds.viewFit(self.cameraName,all=True)
self.modelPanelName = cmds.modelPanel(cam=self.cameraName,parent=paneLayoutName)

# edit model panel
modelEditorValue = cmds.modelPanel(self.modelPanelName,q=True,me=True)
cmds.modelEditor(modelEditorValue,e=True,da='smoothShaded',ca=False,grid=False,hud=False,\
manipulators=False,displayTextures=True,ha=False,j=False,ikh=False,df=False,\
dim=False,lc=False,nc=True,wos=False,dl='default',av=False)

# find a pointer to the modelPanel that we just created
ptr = OpenMayaUI.MQtUtil.findControl(self.modelPanelName)
#wrap the pointer into a python QObject
self.modelPanel = sip.wrapinstance(long(ptr),QtCore.QObject)
#add our QObject reference to the paneLayout to our layout
self.verticalLayout.addWidget(self.paneLayout)
self.verticalLayout.addLayout(butLayout)
self.verticalLayout.setSpacing(0)
self.setLayout(self.verticalLayout)

self.setFixedSize(400,600)

class MainWin(QtGui.QDialog):
def __init__(self,parent=getMayaWindow()):
super(MainWin,self).__init__(parent)
cam = MayaView()
# self.setObjectName('xxxxxx')
but = QtGui.QPushButton('zzz')
layout = QtGui.QVBoxLayout()
layout.addWidget(but)
layout.addWidget(cam)
self.setLayout(layout)
# layout.setObjectName('yyyyy')

a = MainWin()
a.show()





example2:

from PyQt4 import QtCore,QtGui

import maya.cmds as cmds
import maya.OpenMayaUI as OpenMayaUI
import sip
def getMayaWindow():
windowPointer = OpenMayaUI.MQtUtil.mainWindow()
return sip.wrapinstance(long(windowPointer), QtCore.QObject)
class MayaView(QtGui.QWidget):
def __init__(self,parent=None,**kwargs):
super(MayaView,self).__init__(parent,**kwargs)

self.setObjectName('MyWindow')

self.setWindowTitle('3dView')

self.verticalLayout = QtGui.QVBoxLayout(self)
self.verticalLayout.setContentsMargins(0,0,0,0)
self.verticalLayout.setObjectName("mainLayout")


applyBut = QtGui.QPushButton('Apply')
closeBut = QtGui.QPushButton('Close')
butLayout = QtGui.QHBoxLayout()
butLayout.addWidget(applyBut)
butLayout.addWidget(closeBut)

layout = OpenMayaUI.MQtUtil.fullName(long(sip.unwrapinstance(self.verticalLayout)))
cmds.setParent(layout)

paneLayoutName = cmds.paneLayout()
# find a pointer to the paneLayout that we just created
ptr = OpenMayaUI.MQtUtil.findControl(paneLayoutName)
# warp the pointer into a python QObject
self.paneLayout = sip.wrapinstance(long(ptr),QtCore.QObject)

# new create a camera
self.cameraName = cmds.camera(n='PickerView_camera')[0]
cmds.hide(self.cameraName)
cmds.viewFit(self.cameraName,all=True)

self.modelPanelName = cmds.modelPanel(cam=self.cameraName)
cmds.panel(self.modelPanelName,e=True,mbv=False)
flayout = cmds.modelPanel(self.modelPanelName,q=True,barLayout=True)
cmds.frameLayout(flayout,e=True,collapse=True)
# edit model panel
modelEditorValue = cmds.modelPanel(self.modelPanelName,q=True,me=True)
cmds.modelEditor(modelEditorValue,e=True,da='smoothShaded',ca=False,grid=False,hud=False,\
manipulators=False,displayTextures=True,ha=False,j=False,ikh=False,df=False,\
dim=False,lc=False,nc=True,wos=False,dl='default',av=False)

# find a pointer to the modelPanel that we just created
ptr = OpenMayaUI.MQtUtil.findControl(self.modelPanelName)
#wrap the pointer into a python QObject
self.modelPanel = sip.wrapinstance(long(ptr),QtCore.QObject)
#add our QObject reference to the paneLayout to our layout
self.verticalLayout.addWidget(self.paneLayout)
self.verticalLayout.addLayout(butLayout)
self.verticalLayout.setSpacing(0)
self.setLayout(self.verticalLayout)

self.setFixedSize(400,600)

class MainWin(QtGui.QMainWindow):
def __init__(self,parent=getMayaWindow()):
super(MainWin,self).__init__(parent)
self.setObjectName('QtMainWindow')
self.mid = QtGui.QMdiArea()
self.mid.setObjectName('QMdiArea')
self.setCentralWidget(self.mid)


cam = MayaView()

self.mid.addSubWindow(cam)
a = MainWin()
a.show()



--
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 python_inside_maya+***@googlegroups.com<mailto:python_inside_maya+***@googlegroups.com>.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/dfa30f8a-617b-4e4b-8aac-f373054739db%40googlegroups.com<https://groups.google.com/d/msgid/python_inside_maya/dfa30f8a-617b-4e4b-8aac-f373054739db%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.

--
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 python_inside_maya+***@googlegroups.com<mailto:python_inside_maya+***@googlegroups.com>.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA16iJOC3rq-OviFM2zX6TzwUUmQWz184f-VEHnoBwZ9PA%40mail.gmail.com<https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA16iJOC3rq-OviFM2zX6TzwUUmQWz184f-VEHnoBwZ9PA%40mail.gmail.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.
--
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 python_inside_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/BL0PR02MB363517A5490B81A69CEC8B85D3320%40BL0PR02MB3635.namprd02.prod.outlook.com.
For more options, visit https://groups.google.com/d/optout.
Timothy Kim
2018-08-23 16:35:46 UTC
Permalink
Hey Justin,


It seems like putting the paneLayout into a QSplitter causes the issue. I edited your code to add the splitter.




________________________________
From: ***@googlegroups.com <***@googlegroups.com> on behalf of Timothy Kim <***@themill.com>
Sent: Monday, August 20, 2018 9:44:08 AM
To: ***@googlegroups.com
Subject: [MailingList] Re: [Maya-Python] Re: How to embed modelPanel to a pyqt ui (again) ?


Thank Justin. I don't have access to my code right now to check the differences between mine and this one but this code works perfectly fine. Thanks again.

________________________________
From: ***@googlegroups.com <***@googlegroups.com> on behalf of Justin Israel <***@gmail.com>
Sent: Sunday, August 19, 2018 9:37:26 PM
To: ***@googlegroups.com
Subject: Re: [Maya-Python] Re: How to embed modelPanel to a pyqt ui (again) ?

** Incoming mail from outside The Mill **



On Sat, Aug 18, 2018 at 4:14 AM tim2018 <***@themill.com<mailto:***@themill.com>> wrote:
Hello, Thanks for the examples but I noticed that none of the icons in modelEditorIconBar seem to work. Clicking on shaded or wireframe icons have no effect in the viewport. Does anyone know how to fix this problem? I am referring to example1.

Thanks

I've updated the original blog post with a Maya >= 2017 port of that example code:
http://justinfx.com/2011/11/20/mixing-pyqt4-widgets-and-maya-ui-objects/

I tested it in Maya 2018 and it seems like the toolbar icons in the model editor worked just fine. Can you confirm?



On Friday, 23 May 2014 13:50:56 UTC-4, oglop wrote:
i know this <http:///> has been asked<https://groups.google.com/forum/#!topic/python_inside_maya/wioChE9IFDA> on 2011 and Justine has an awesome example here<https://gist.github.com/justinfx/1381489>
you saw the last few lines i commented out the setObjectName xxxx and yyyyy, without them, when you run the code in maya, it successfully opens the ui, but when you press 4 or 5 on the modelPanel, you will see the following error message similar to :

updateModelPanelBar MayaWindow|||formLayout1|viewPanes|modelPanel4|modelPanel5|modelPanel5;

notice the ||| part.

it seems as if without object names set, maya doesn't know how to find the newly created modelPanel. also if i'm using mainwindow i also see this error unless i set object names using an awkward workaround.

example1

from PyQt4 import QtCore,QtGui

import maya.cmds as cmds
import maya.OpenMayaUI as OpenMayaUI
import sip

def getMayaWindow():
windowPointer = OpenMayaUI.MQtUtil.mainWindow()
return sip.wrapinstance(long(windowPointer), QtCore.QObject)

class MayaView(QtGui.QDialog):
def __init__(self,parent=None,**kwargs):
super(MayaView,self).__init__(parent,**kwargs)

self.setObjectName('MyWindow')

self.setWindowTitle('3dView')

self.verticalLayout = QtGui.QVBoxLayout(self)
self.verticalLayout.setContentsMargins(0,0,0,0)
self.verticalLayout.setObjectName("mainLayout")

applyBut = QtGui.QPushButton('Apply')
closeBut = QtGui.QPushButton('Close')
butLayout = QtGui.QHBoxLayout()
butLayout.addWidget(applyBut)
butLayout.addWidget(closeBut)
butLayout.setObjectName("xxxBut")

layout = OpenMayaUI.MQtUtil.fullName(long(sip.unwrapinstance(self.verticalLayout)))
print "vertical layout",layout

cmds.setParent(layout)

paneLayoutName = cmds.paneLayout()
# find a pointer to the paneLayout that we just created
ptr = OpenMayaUI.MQtUtil.findControl(paneLayoutName)
# warp the pointer into a python QObject
self.paneLayout = sip.wrapinstance(long(ptr),QtCore.QObject)

# new create a camera
self.cameraName = cmds.camera(n='PickerView_camera')[0]
cmds.hide(self.cameraName)
cmds.viewFit(self.cameraName,all=True)
self.modelPanelName = cmds.modelPanel(cam=self.cameraName,parent=paneLayoutName)

# edit model panel
modelEditorValue = cmds.modelPanel(self.modelPanelName,q=True,me=True)
cmds.modelEditor(modelEditorValue,e=True,da='smoothShaded',ca=False,grid=False,hud=False,\
manipulators=False,displayTextures=True,ha=False,j=False,ikh=False,df=False,\
dim=False,lc=False,nc=True,wos=False,dl='default',av=False)

# find a pointer to the modelPanel that we just created
ptr = OpenMayaUI.MQtUtil.findControl(self.modelPanelName)
#wrap the pointer into a python QObject
self.modelPanel = sip.wrapinstance(long(ptr),QtCore.QObject)
#add our QObject reference to the paneLayout to our layout
self.verticalLayout.addWidget(self.paneLayout)
self.verticalLayout.addLayout(butLayout)
self.verticalLayout.setSpacing(0)
self.setLayout(self.verticalLayout)

self.setFixedSize(400,600)

class MainWin(QtGui.QDialog):
def __init__(self,parent=getMayaWindow()):
super(MainWin,self).__init__(parent)
cam = MayaView()
# self.setObjectName('xxxxxx')
but = QtGui.QPushButton('zzz')
layout = QtGui.QVBoxLayout()
layout.addWidget(but)
layout.addWidget(cam)
self.setLayout(layout)
# layout.setObjectName('yyyyy')

a = MainWin()
a.show()





example2:

from PyQt4 import QtCore,QtGui

import maya.cmds as cmds
import maya.OpenMayaUI as OpenMayaUI
import sip
def getMayaWindow():
windowPointer = OpenMayaUI.MQtUtil.mainWindow()
return sip.wrapinstance(long(windowPointer), QtCore.QObject)
class MayaView(QtGui.QWidget):
def __init__(self,parent=None,**kwargs):
super(MayaView,self).__init__(parent,**kwargs)

self.setObjectName('MyWindow')

self.setWindowTitle('3dView')

self.verticalLayout = QtGui.QVBoxLayout(self)
self.verticalLayout.setContentsMargins(0,0,0,0)
self.verticalLayout.setObjectName("mainLayout")


applyBut = QtGui.QPushButton('Apply')
closeBut = QtGui.QPushButton('Close')
butLayout = QtGui.QHBoxLayout()
butLayout.addWidget(applyBut)
butLayout.addWidget(closeBut)

layout = OpenMayaUI.MQtUtil.fullName(long(sip.unwrapinstance(self.verticalLayout)))
cmds.setParent(layout)

paneLayoutName = cmds.paneLayout()
# find a pointer to the paneLayout that we just created
ptr = OpenMayaUI.MQtUtil.findControl(paneLayoutName)
# warp the pointer into a python QObject
self.paneLayout = sip.wrapinstance(long(ptr),QtCore.QObject)

# new create a camera
self.cameraName = cmds.camera(n='PickerView_camera')[0]
cmds.hide(self.cameraName)
cmds.viewFit(self.cameraName,all=True)

self.modelPanelName = cmds.modelPanel(cam=self.cameraName)
cmds.panel(self.modelPanelName,e=True,mbv=False)
flayout = cmds.modelPanel(self.modelPanelName,q=True,barLayout=True)
cmds.frameLayout(flayout,e=True,collapse=True)
# edit model panel
modelEditorValue = cmds.modelPanel(self.modelPanelName,q=True,me=True)
cmds.modelEditor(modelEditorValue,e=True,da='smoothShaded',ca=False,grid=False,hud=False,\
manipulators=False,displayTextures=True,ha=False,j=False,ikh=False,df=False,\
dim=False,lc=False,nc=True,wos=False,dl='default',av=False)

# find a pointer to the modelPanel that we just created
ptr = OpenMayaUI.MQtUtil.findControl(self.modelPanelName)
#wrap the pointer into a python QObject
self.modelPanel = sip.wrapinstance(long(ptr),QtCore.QObject)
#add our QObject reference to the paneLayout to our layout
self.verticalLayout.addWidget(self.paneLayout)
self.verticalLayout.addLayout(butLayout)
self.verticalLayout.setSpacing(0)
self.setLayout(self.verticalLayout)

self.setFixedSize(400,600)

class MainWin(QtGui.QMainWindow):
def __init__(self,parent=getMayaWindow()):
super(MainWin,self).__init__(parent)
self.setObjectName('QtMainWindow')
self.mid = QtGui.QMdiArea()
self.mid.setObjectName('QMdiArea')
self.setCentralWidget(self.mid)


cam = MayaView()

self.mid.addSubWindow(cam)
a = MainWin()
a.show()



--
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 python_inside_maya+***@googlegroups.com<mailto:python_inside_maya+***@googlegroups.com>.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/dfa30f8a-617b-4e4b-8aac-f373054739db%40googlegroups.com<https://groups.google.com/d/msgid/python_inside_maya/dfa30f8a-617b-4e4b-8aac-f373054739db%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.

--
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 python_inside_maya+***@googlegroups.com<mailto:python_inside_maya+***@googlegroups.com>.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA16iJOC3rq-OviFM2zX6TzwUUmQWz184f-VEHnoBwZ9PA%40mail.gmail.com<https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA16iJOC3rq-OviFM2zX6TzwUUmQWz184f-VEHnoBwZ9PA%40mail.gmail.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.

--
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 python_inside_maya+***@googlegroups.com<mailto:python_inside_maya+***@googlegroups.com>.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/BL0PR02MB363517A5490B81A69CEC8B85D3320%40BL0PR02MB3635.namprd02.prod.outlook.com<https://groups.google.com/d/msgid/python_inside_maya/BL0PR02MB363517A5490B81A69CEC8B85D3320%40BL0PR02MB3635.namprd02.prod.outlook.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.
--
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 python_inside_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/DM5PR02MB3637073DF0D9409BEA9698F4D3370%40DM5PR02MB3637.namprd02.prod.outlook.com.
For more options, visit https://groups.google.com/d/optout.
Timothy Kim
2018-08-23 16:37:13 UTC
Permalink
Running the code below adds the splitter. Do you know if there's a work around for this?

Thanks

from PySide2 import QtCore, QtWidgets
import shiboken2

import maya.cmds as cmds
import maya.OpenMayaUI as mui


#class MyDialog(QtWidgets.QDialog):
class MyDialog(QtWidgets.QMainWindow):

def __init__(self, parent, **kwargs):
super(MyDialog, self).__init__(parent, **kwargs)

self.setObjectName("MyWindow")
self.resize(800, 600)
self.setWindowTitle("PyQt ModelPanel Test")

self.central_widget = QtWidgets.QWidget()
self.setCentralWidget(self.central_widget)

#self.verticalLayout = QtWidgets.QVBoxLayout(self)
self.verticalLayout = QtWidgets.QVBoxLayout(self.central_widget)
self.verticalLayout.setContentsMargins(0,0,0,0)

# need to set a name so it can be referenced by maya node path
self.verticalLayout.setObjectName("mainLayout")

# First use SIP to unwrap the layout into a pointer
# Then get the full path to the UI in maya as a string
layout = mui.MQtUtil.fullName(long(shiboken2.getCppPointer(self.verticalLayout)[0]))
cmds.setParent(layout)

paneLayoutName = cmds.paneLayout()

# Find a pointer to the paneLayout that we just created
ptr = mui.MQtUtil.findControl(paneLayoutName)

# Wrap the pointer into a python QObject
self.paneLayout = shiboken2.wrapInstance(long(ptr), QtWidgets.QWidget)

self.cameraName = cmds.camera()[0]
self.modelPanelName = cmds.modelPanel("customModelPanel#", label="ModelPanel Test", cam=self.cameraName)


timeline = cmds.timePort('cameraViewerTimePort')
time_ptr = mui.MQtUtil.findControl(timeline)
self.timePaneLayout = shiboken2.wrapInstance(long(time_ptr), QtWidgets.QWidget)


# Find a pointer to the modelPanel that we just created
ptr = mui.MQtUtil.findControl(self.modelPanelName)

# Wrap the pointer into a python QObject
self.modelPanel = shiboken2.wrapInstance(long(ptr), QtWidgets.QWidget)

splitter1 = QtWidgets.QSplitter(QtCore.Qt.Vertical)

splitter1.addWidget(self.paneLayout)
splitter1.addWidget(self.timePaneLayout)
splitter1.setSizes([500, 200])


# add our QObject reference to the paneLayout to our layout
#self.verticalLayout.addWidget(self.paneLayout)
self.verticalLayout.addWidget(splitter1)



def showEvent(self, event):
super(MyDialog, self).showEvent(event)

# maya can lag in how it repaints UI. Force it to repaint
# when we show the window.
self.modelPanel.repaint()


def show():
# get a pointer to the maya main window
ptr = mui.MQtUtil.mainWindow()
# use sip to wrap the pointer into a QObject
win = shiboken2.wrapInstance(long(ptr), QtWidgets.QWidget)
d = MyDialog(win)
d.show()

return d


try:
dialog.deleteLater()
except:
pass
dialog = show()


________________________________
From: Timothy Kim
Sent: Thursday, August 23, 2018 12:35:46 PM
To: ***@googlegroups.com
Subject: Re: [Maya-Python] Re: How to embed modelPanel to a pyqt ui (again) ?


Hey Justin,


It seems like putting the paneLayout into a QSplitter causes the issue. I edited your code to add the splitter.




________________________________
From: ***@googlegroups.com <***@googlegroups.com> on behalf of Timothy Kim <***@themill.com>
Sent: Monday, August 20, 2018 9:44:08 AM
To: ***@googlegroups.com
Subject: [MailingList] Re: [Maya-Python] Re: How to embed modelPanel to a pyqt ui (again) ?


Thank Justin. I don't have access to my code right now to check the differences between mine and this one but this code works perfectly fine. Thanks again.

________________________________
From: ***@googlegroups.com <***@googlegroups.com> on behalf of Justin Israel <***@gmail.com>
Sent: Sunday, August 19, 2018 9:37:26 PM
To: ***@googlegroups.com
Subject: Re: [Maya-Python] Re: How to embed modelPanel to a pyqt ui (again) ?

** Incoming mail from outside The Mill **



On Sat, Aug 18, 2018 at 4:14 AM tim2018 <***@themill.com<mailto:***@themill.com>> wrote:
Hello, Thanks for the examples but I noticed that none of the icons in modelEditorIconBar seem to work. Clicking on shaded or wireframe icons have no effect in the viewport. Does anyone know how to fix this problem? I am referring to example1.

Thanks

I've updated the original blog post with a Maya >= 2017 port of that example code:
http://justinfx.com/2011/11/20/mixing-pyqt4-widgets-and-maya-ui-objects/

I tested it in Maya 2018 and it seems like the toolbar icons in the model editor worked just fine. Can you confirm?



On Friday, 23 May 2014 13:50:56 UTC-4, oglop wrote:
i know this <http:///> has been asked<https://groups.google.com/forum/#!topic/python_inside_maya/wioChE9IFDA> on 2011 and Justine has an awesome example here<https://gist.github.com/justinfx/1381489>
you saw the last few lines i commented out the setObjectName xxxx and yyyyy, without them, when you run the code in maya, it successfully opens the ui, but when you press 4 or 5 on the modelPanel, you will see the following error message similar to :

updateModelPanelBar MayaWindow|||formLayout1|viewPanes|modelPanel4|modelPanel5|modelPanel5;

notice the ||| part.

it seems as if without object names set, maya doesn't know how to find the newly created modelPanel. also if i'm using mainwindow i also see this error unless i set object names using an awkward workaround.

example1

from PyQt4 import QtCore,QtGui

import maya.cmds as cmds
import maya.OpenMayaUI as OpenMayaUI
import sip

def getMayaWindow():
windowPointer = OpenMayaUI.MQtUtil.mainWindow()
return sip.wrapinstance(long(windowPointer), QtCore.QObject)

class MayaView(QtGui.QDialog):
def __init__(self,parent=None,**kwargs):
super(MayaView,self).__init__(parent,**kwargs)

self.setObjectName('MyWindow')

self.setWindowTitle('3dView')

self.verticalLayout = QtGui.QVBoxLayout(self)
self.verticalLayout.setContentsMargins(0,0,0,0)
self.verticalLayout.setObjectName("mainLayout")

applyBut = QtGui.QPushButton('Apply')
closeBut = QtGui.QPushButton('Close')
butLayout = QtGui.QHBoxLayout()
butLayout.addWidget(applyBut)
butLayout.addWidget(closeBut)
butLayout.setObjectName("xxxBut")

layout = OpenMayaUI.MQtUtil.fullName(long(sip.unwrapinstance(self.verticalLayout)))
print "vertical layout",layout

cmds.setParent(layout)

paneLayoutName = cmds.paneLayout()
# find a pointer to the paneLayout that we just created
ptr = OpenMayaUI.MQtUtil.findControl(paneLayoutName)
# warp the pointer into a python QObject
self.paneLayout = sip.wrapinstance(long(ptr),QtCore.QObject)

# new create a camera
self.cameraName = cmds.camera(n='PickerView_camera')[0]
cmds.hide(self.cameraName)
cmds.viewFit(self.cameraName,all=True)
self.modelPanelName = cmds.modelPanel(cam=self.cameraName,parent=paneLayoutName)

# edit model panel
modelEditorValue = cmds.modelPanel(self.modelPanelName,q=True,me=True)
cmds.modelEditor(modelEditorValue,e=True,da='smoothShaded',ca=False,grid=False,hud=False,\
manipulators=False,displayTextures=True,ha=False,j=False,ikh=False,df=False,\
dim=False,lc=False,nc=True,wos=False,dl='default',av=False)

# find a pointer to the modelPanel that we just created
ptr = OpenMayaUI.MQtUtil.findControl(self.modelPanelName)
#wrap the pointer into a python QObject
self.modelPanel = sip.wrapinstance(long(ptr),QtCore.QObject)
#add our QObject reference to the paneLayout to our layout
self.verticalLayout.addWidget(self.paneLayout)
self.verticalLayout.addLayout(butLayout)
self.verticalLayout.setSpacing(0)
self.setLayout(self.verticalLayout)

self.setFixedSize(400,600)

class MainWin(QtGui.QDialog):
def __init__(self,parent=getMayaWindow()):
super(MainWin,self).__init__(parent)
cam = MayaView()
# self.setObjectName('xxxxxx')
but = QtGui.QPushButton('zzz')
layout = QtGui.QVBoxLayout()
layout.addWidget(but)
layout.addWidget(cam)
self.setLayout(layout)
# layout.setObjectName('yyyyy')

a = MainWin()
a.show()





example2:

from PyQt4 import QtCore,QtGui

import maya.cmds as cmds
import maya.OpenMayaUI as OpenMayaUI
import sip
def getMayaWindow():
windowPointer = OpenMayaUI.MQtUtil.mainWindow()
return sip.wrapinstance(long(windowPointer), QtCore.QObject)
class MayaView(QtGui.QWidget):
def __init__(self,parent=None,**kwargs):
super(MayaView,self).__init__(parent,**kwargs)

self.setObjectName('MyWindow')

self.setWindowTitle('3dView')

self.verticalLayout = QtGui.QVBoxLayout(self)
self.verticalLayout.setContentsMargins(0,0,0,0)
self.verticalLayout.setObjectName("mainLayout")


applyBut = QtGui.QPushButton('Apply')
closeBut = QtGui.QPushButton('Close')
butLayout = QtGui.QHBoxLayout()
butLayout.addWidget(applyBut)
butLayout.addWidget(closeBut)

layout = OpenMayaUI.MQtUtil.fullName(long(sip.unwrapinstance(self.verticalLayout)))
cmds.setParent(layout)

paneLayoutName = cmds.paneLayout()
# find a pointer to the paneLayout that we just created
ptr = OpenMayaUI.MQtUtil.findControl(paneLayoutName)
# warp the pointer into a python QObject
self.paneLayout = sip.wrapinstance(long(ptr),QtCore.QObject)

# new create a camera
self.cameraName = cmds.camera(n='PickerView_camera')[0]
cmds.hide(self.cameraName)
cmds.viewFit(self.cameraName,all=True)

self.modelPanelName = cmds.modelPanel(cam=self.cameraName)
cmds.panel(self.modelPanelName,e=True,mbv=False)
flayout = cmds.modelPanel(self.modelPanelName,q=True,barLayout=True)
cmds.frameLayout(flayout,e=True,collapse=True)
# edit model panel
modelEditorValue = cmds.modelPanel(self.modelPanelName,q=True,me=True)
cmds.modelEditor(modelEditorValue,e=True,da='smoothShaded',ca=False,grid=False,hud=False,\
manipulators=False,displayTextures=True,ha=False,j=False,ikh=False,df=False,\
dim=False,lc=False,nc=True,wos=False,dl='default',av=False)

# find a pointer to the modelPanel that we just created
ptr = OpenMayaUI.MQtUtil.findControl(self.modelPanelName)
#wrap the pointer into a python QObject
self.modelPanel = sip.wrapinstance(long(ptr),QtCore.QObject)
#add our QObject reference to the paneLayout to our layout
self.verticalLayout.addWidget(self.paneLayout)
self.verticalLayout.addLayout(butLayout)
self.verticalLayout.setSpacing(0)
self.setLayout(self.verticalLayout)

self.setFixedSize(400,600)

class MainWin(QtGui.QMainWindow):
def __init__(self,parent=getMayaWindow()):
super(MainWin,self).__init__(parent)
self.setObjectName('QtMainWindow')
self.mid = QtGui.QMdiArea()
self.mid.setObjectName('QMdiArea')
self.setCentralWidget(self.mid)


cam = MayaView()

self.mid.addSubWindow(cam)
a = MainWin()
a.show()



--
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 python_inside_maya+***@googlegroups.com<mailto:python_inside_maya+***@googlegroups.com>.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/dfa30f8a-617b-4e4b-8aac-f373054739db%40googlegroups.com<https://groups.google.com/d/msgid/python_inside_maya/dfa30f8a-617b-4e4b-8aac-f373054739db%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.

--
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 python_inside_maya+***@googlegroups.com<mailto:python_inside_maya+***@googlegroups.com>.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA16iJOC3rq-OviFM2zX6TzwUUmQWz184f-VEHnoBwZ9PA%40mail.gmail.com<https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA16iJOC3rq-OviFM2zX6TzwUUmQWz184f-VEHnoBwZ9PA%40mail.gmail.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.

--
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 python_inside_maya+***@googlegroups.com<mailto:python_inside_maya+***@googlegroups.com>.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/BL0PR02MB363517A5490B81A69CEC8B85D3320%40BL0PR02MB3635.namprd02.prod.outlook.com<https://groups.google.com/d/msgid/python_inside_maya/BL0PR02MB363517A5490B81A69CEC8B85D3320%40BL0PR02MB3635.namprd02.prod.outlook.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.
--
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 python_inside_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/DM5PR02MB36377ECD33C4A72D151B822DD3370%40DM5PR02MB3637.namprd02.prod.outlook.com.
For more options, visit https://groups.google.com/d/optout.
Justin Israel
2018-08-23 21:42:47 UTC
Permalink
I don't really have an answer for you on this one. I tried to shuffle
things around in your latest code example, and tried even creating an
intermediate widget+layout between the splitter and the paneLayout, but the
behaviour did not change. Don't forget, this is all a hack on the Maya UI
so its not unreasonable for things to work incorrectly :-)
Post by Timothy Kim
Running the code below adds the splitter. Do you know if there's a work around for this?
Thanks
from PySide2 import QtCore, QtWidgets
import shiboken2
import maya.cmds as cmds
import maya.OpenMayaUI as mui
super(MyDialog, self).__init__(parent, **kwargs)
self.setObjectName("MyWindow")
self.resize(800, 600)
self.setWindowTitle("PyQt ModelPanel Test")
self.central_widget = QtWidgets.QWidget()
self.setCentralWidget(self.central_widget)
#self.verticalLayout = QtWidgets.QVBoxLayout(self)
self.verticalLayout = QtWidgets.QVBoxLayout(self.central_widget)
self.verticalLayout.setContentsMargins(0,0,0,0)
# need to set a name so it can be referenced by maya node path
self.verticalLayout.setObjectName("mainLayout")
# First use SIP to unwrap the layout into a pointer
# Then get the full path to the UI in maya as a string
layout =
mui.MQtUtil.fullName(long(shiboken2.getCppPointer(self.verticalLayout)[0]))
cmds.setParent(layout)
paneLayoutName = cmds.paneLayout()
# Find a pointer to the paneLayout that we just created
ptr = mui.MQtUtil.findControl(paneLayoutName)
# Wrap the pointer into a python QObject
self.paneLayout = shiboken2.wrapInstance(long(ptr),
QtWidgets.QWidget)
self.cameraName = cmds.camera()[0]
self.modelPanelName = cmds.modelPanel("customModelPanel#",
label="ModelPanel Test", cam=self.cameraName)
timeline = cmds.timePort('cameraViewerTimePort')
time_ptr = mui.MQtUtil.findControl(timeline)
self.timePaneLayout = shiboken2.wrapInstance(long(time_ptr), QtWidgets.QWidget)
# Find a pointer to the modelPanel that we just created
ptr = mui.MQtUtil.findControl(self.modelPanelName)
# Wrap the pointer into a python QObject
self.modelPanel = shiboken2.wrapInstance(long(ptr),
QtWidgets.QWidget)
splitter1 = QtWidgets.QSplitter(QtCore.Qt.Vertical)
splitter1.addWidget(self.paneLayout)
splitter1.addWidget(self.timePaneLayout)
splitter1.setSizes([500, 200])
# add our QObject reference to the paneLayout to our layout
#self.verticalLayout.addWidget(self.paneLayout)
self.verticalLayout.addWidget(splitter1)
super(MyDialog, self).showEvent(event)
# maya can lag in how it repaints UI. Force it to repaint
# when we show the window.
self.modelPanel.repaint()
# get a pointer to the maya main window
ptr = mui.MQtUtil.mainWindow()
# use sip to wrap the pointer into a QObject
win = shiboken2.wrapInstance(long(ptr), QtWidgets.QWidget)
d = MyDialog(win)
d.show()
return d
dialog.deleteLater()
pass
dialog = show()
------------------------------
*From:* Timothy Kim
*Sent:* Thursday, August 23, 2018 12:35:46 PM
*Subject:* Re: [Maya-Python] Re: How to embed modelPanel to a pyqt ui
(again) ?
Hey Justin,
It seems like putting the paneLayout into a QSplitter causes the issue. I
edited your code to add the splitter.
------------------------------
*Sent:* Monday, August 20, 2018 9:44:08 AM
*Subject:* [MailingList] Re: [Maya-Python] Re: How to embed modelPanel to
a pyqt ui (again) ?
Thank Justin. I don't have access to my code right now to check the
differences between mine and this one but this code works perfectly fine.
Thanks again.
------------------------------
*Sent:* Sunday, August 19, 2018 9:37:26 PM
*Subject:* Re: [Maya-Python] Re: How to embed modelPanel to a pyqt ui
(again) ?
** Incoming mail from outside The Mill **
Hello, Thanks for the examples but I noticed that none of the icons in
modelEditorIconBar seem to work. Clicking on shaded or wireframe icons have
no effect in the viewport. Does anyone know how to fix this problem? I am
referring to example1.
Thanks
http://justinfx.com/2011/11/20/mixing-pyqt4-widgets-and-maya-ui-objects/
I tested it in Maya 2018 and it seems like the toolbar icons in the model
editor worked just fine. Can you confirm?
i know this has been asked
<https://groups.google.com/forum/#!topic/python_inside_maya/wioChE9IFDA>
on 2011 and Justine has an awesome example here
<https://gist.github.com/justinfx/1381489>
you saw the last few lines i commented out the setObjectName xxxx and
yyyyy, without them, when you run the code in maya, it successfully opens
the ui, but when you press 4 or 5 on the modelPanel, you will see the
updateModelPanelBar
MayaWindow|||formLayout1|viewPanes|modelPanel4|modelPanel5|modelPanel5;
notice the ||| part.
it seems as if without object names set, maya doesn't know how to find the
newly created modelPanel. also if i'm using mainwindow i also see this
error unless i set object names using an awkward workaround.
example1
from PyQt4 import QtCore,QtGui
import maya.cmds as cmds
import maya.OpenMayaUI as OpenMayaUI
import sip
windowPointer = OpenMayaUI.MQtUtil.mainWindow()
return sip.wrapinstance(long(windowPointer), QtCore.QObject)
super(MayaView,self).__init__(parent,**kwargs)
self.setObjectName('MyWindow')
self.setWindowTitle('3dView')
self.verticalLayout = QtGui.QVBoxLayout(self)
self.verticalLayout.setContentsMargins(0,0,0,0)
self.verticalLayout.setObjectName("mainLayout")
applyBut = QtGui.QPushButton('Apply')
closeBut = QtGui.QPushButton('Close')
butLayout = QtGui.QHBoxLayout()
butLayout.addWidget(applyBut)
butLayout.addWidget(closeBut)
butLayout.setObjectName("xxxBut")
layout = OpenMayaUI.MQtUtil.fullName(long(sip.unwrapinstance(self.
verticalLayout)))
print "vertical layout",layout
cmds.setParent(layout)
paneLayoutName = cmds.paneLayout()
# find a pointer to the paneLayout that we just created
ptr = OpenMayaUI.MQtUtil.findControl(paneLayoutName)
# warp the pointer into a python QObject
self.paneLayout = sip.wrapinstance(long(ptr),QtCore.QObject)
# new create a camera
self.cameraName = cmds.camera(n='PickerView_camera')[0]
cmds.hide(self.cameraName)
cmds.viewFit(self.cameraName,all=True)
self.modelPanelName = cmds.modelPanel(cam=self.cameraName,parent=
paneLayoutName)
# edit model panel
modelEditorValue = cmds.modelPanel(self.modelPanelName,q=True,me=
True)
cmds.modelEditor(modelEditorValue,e=True,da='smoothShaded',ca=
False,grid=False,hud=False,\
manipulators=False,displayTextures=True,ha=False,
j=False,ikh=False,df=False,\
dim=False,lc=False,nc=True,wos=False,dl='default'
,av=False)
# find a pointer to the modelPanel that we just created
ptr = OpenMayaUI.MQtUtil.findControl(self.modelPanelName)
#wrap the pointer into a python QObject
self.modelPanel = sip.wrapinstance(long(ptr),QtCore.QObject)
#add our QObject reference to the paneLayout to our layout
self.verticalLayout.addWidget(self.paneLayout)
self.verticalLayout.addLayout(butLayout)
self.verticalLayout.setSpacing(0)
self.setLayout(self.verticalLayout)
self.setFixedSize(400,600)
super(MainWin,self).__init__(parent)
cam = MayaView()
# self.setObjectName('xxxxxx')
but = QtGui.QPushButton('zzz')
layout = QtGui.QVBoxLayout()
layout.addWidget(but)
layout.addWidget(cam)
self.setLayout(layout)
# layout.setObjectName('yyyyy')
a = MainWin()
a.show()
from PyQt4 import QtCore,QtGui
import maya.cmds as cmds
import maya.OpenMayaUI as OpenMayaUI
import sip
windowPointer = OpenMayaUI.MQtUtil.mainWindow()
return sip.wrapinstance(long(windowPointer), QtCore.QObject)
super(MayaView,self).__init__(parent,**kwargs)
self.setObjectName('MyWindow')
self.setWindowTitle('3dView')
self.verticalLayout = QtGui.QVBoxLayout(self)
self.verticalLayout.setContentsMargins(0,0,0,0)
self.verticalLayout.setObjectName("mainLayout")
applyBut = QtGui.QPushButton('Apply')
closeBut = QtGui.QPushButton('Close')
butLayout = QtGui.QHBoxLayout()
butLayout.addWidget(applyBut)
butLayout.addWidget(closeBut)
layout = OpenMayaUI.MQtUtil.fullName(long(sip.unwrapinstance(self.
verticalLayout)))
cmds.setParent(layout)
paneLayoutName = cmds.paneLayout()
# find a pointer to the paneLayout that we just created
ptr = OpenMayaUI.MQtUtil.findControl(paneLayoutName)
# warp the pointer into a python QObject
self.paneLayout = sip.wrapinstance(long(ptr),QtCore.QObject)
# new create a camera
self.cameraName = cmds.camera(n='PickerView_camera')[0]
cmds.hide(self.cameraName)
cmds.viewFit(self.cameraName,all=True)
self.modelPanelName = cmds.modelPanel(cam=self.cameraName)
cmds.panel(self.modelPanelName,e=True,mbv=False)
flayout = cmds.modelPanel(self.modelPanelName,q=True,barLayout=
True)
cmds.frameLayout(flayout,e=True,collapse=True)
# edit model panel
modelEditorValue = cmds.modelPanel(self.modelPanelName,q=True,me=
True)
cmds.modelEditor(modelEditorValue,e=True,da='smoothShaded',ca=
False,grid=False,hud=False,\
manipulators=False,displayTextures=True,ha=False,
j=False,ikh=False,df=False,\
dim=False,lc=False,nc=True,wos=False,dl='default'
,av=False)
# find a pointer to the modelPanel that we just created
ptr = OpenMayaUI.MQtUtil.findControl(self.modelPanelName)
#wrap the pointer into a python QObject
self.modelPanel = sip.wrapinstance(long(ptr),QtCore.QObject)
#add our QObject reference to the paneLayout to our layout
self.verticalLayout.addWidget(self.paneLayout)
self.verticalLayout.addLayout(butLayout)
self.verticalLayout.setSpacing(0)
self.setLayout(self.verticalLayout)
self.setFixedSize(400,600)
super(MainWin,self).__init__(parent)
self.setObjectName('QtMainWindow')
self.mid = QtGui.QMdiArea()
self.mid.setObjectName('QMdiArea')
self.setCentralWidget(self.mid)
cam = MayaView()
self.mid.addSubWindow(cam)
a = MainWin()
a.show()
--
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
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/dfa30f8a-617b-4e4b-8aac-f373054739db%40googlegroups.com
<https://groups.google.com/d/msgid/python_inside_maya/dfa30f8a-617b-4e4b-8aac-f373054739db%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
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
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA16iJOC3rq-OviFM2zX6TzwUUmQWz184f-VEHnoBwZ9PA%40mail.gmail.com
<https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA16iJOC3rq-OviFM2zX6TzwUUmQWz184f-VEHnoBwZ9PA%40mail.gmail.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
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
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/BL0PR02MB363517A5490B81A69CEC8B85D3320%40BL0PR02MB3635.namprd02.prod.outlook.com
<https://groups.google.com/d/msgid/python_inside_maya/BL0PR02MB363517A5490B81A69CEC8B85D3320%40BL0PR02MB3635.namprd02.prod.outlook.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
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
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/DM5PR02MB36377ECD33C4A72D151B822DD3370%40DM5PR02MB3637.namprd02.prod.outlook.com
<https://groups.google.com/d/msgid/python_inside_maya/DM5PR02MB36377ECD33C4A72D151B822DD3370%40DM5PR02MB3637.namprd02.prod.outlook.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
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 python_inside_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA0xyvx17Rp9sTw9_GjDqFjH6c7sRMMpM6Ojth2P4WdChw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Timothy Kim
2018-08-24 13:13:34 UTC
Permalink
Thanks for looking into Justin.


________________________________
From: ***@googlegroups.com <***@googlegroups.com> on behalf of Justin Israel <***@gmail.com>
Sent: Thursday, August 23, 2018 5:42 PM
To: ***@googlegroups.com
Subject: Re: [Maya-Python] Re: How to embed modelPanel to a pyqt ui (again) ?

** Incoming mail from outside The Mill **

I don't really have an answer for you on this one. I tried to shuffle things around in your latest code example, and tried even creating an intermediate widget+layout between the splitter and the paneLayout, but the behaviour did not change. Don't forget, this is all a hack on the Maya UI so its not unreasonable for things to work incorrectly :-)



ups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+***@googlegroups.com<mailto:python_inside_maya+***@googlegroups.com>.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/BL0PR02MB363517A5490B81A69CEC8B85D3320%40BL0PR02MB3635.namprd02.prod.outlook.com<https://groups.google.com/d/msgid/python_inside_maya/BL0PR02MB363517A5490B81A69CEC8B85D3320%40BL0PR02MB3635.namprd02.prod.outlook.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.

--
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 python_inside_maya+***@googlegroups.com<mailto:python_inside_maya+***@googlegroups.com>.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/DM5PR02MB36377ECD33C4A72D151B822DD3370%40DM5PR02MB3637.namprd02.prod.outlook.com<https://groups.google.com/d/msgid/python_inside_maya/DM5PR02MB36377ECD33C4A72D151B822DD3370%40DM5PR02MB3637.namprd02.prod.outlook.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.

--
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 python_inside_maya+***@googlegroups.com<mailto:python_inside_maya+***@googlegroups.com>.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA0xyvx17Rp9sTw9_GjDqFjH6c7sRMMpM6Ojth2P4WdChw%40mail.gmail.com<https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA0xyvx17Rp9sTw9_GjDqFjH6c7sRMMpM6Ojth2P4WdChw%40mail.gmail.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.
--
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 python_inside_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/BL0PR02MB3635005A3EA4B75121871086D3360%40BL0PR02MB3635.namprd02.prod.outlook.com.
For more options, visit https://groups.google.com/d/optout.
tim2018
2018-08-17 16:15:54 UTC
Permalink
Hello, Thanks for the examples but I noticed that none of the icons in
modelEditorIconBar seem to work. Clicking on shaded or wireframe icons have
no effect in the viewport. Does anyone know how to fix this problem? I am
referring to example1.

Thanks
--
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 python_inside_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/57a92038-c10a-4900-b086-5410ddd9e95c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...