Working Fine now.
Here is UI
Code:
import maya.OpenMaya as om
import maya.OpenMayaUI as omUI
import sip
from PyQt4 import QtGui, QtCore, uic
import maya.cmds as cmds
import maya.mel as mel
def getMayaWindow():
# 'Get the maya main window as a QMainWindow instance'
ptr = omUI.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 = omUI.MQtUtil.findControl(mayaName)
if ptr is None:
ptr = omUI.MQtUtil.findLayout(mayaName)
if ptr is None:
ptr = omUI.MQtUtil.findMenuItem(mayaName)
if ptr is not None:
return sip.wrapinstance(long(ptr), QtCore.QObject)
uiFile = ('D:/modEditorTestUI.ui')
form_class, base_class = uic.loadUiType(uiFile)
class myUIClass(form_class, base_class):
def __init__(self, parent=getMayaWindow()):
super(myUIClass, self).__init__(parent)
self.setupUi( self )
if mc.modelEditor('snapEditor', query=True, exists=True):
mc.deleteUI('snapEditor', editor=True )
self.snapView = mc.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)
qtObj = toQtObject(self.snapView)
self.p1_vbox = QtGui.QVBoxLayout(self.modelFrame)
self.p1_vbox.addWidget(qtObj)
qtObj.setMinimumSize(QtCore.QSize(256, 256))
#self.setCentralWidget(qtObj)
#methods
self.connectSignals()
def connectSignals(self):
"""Connect all the UI signals"""
self.connect(self.snapshotBtn, QtCore.SIGNAL('released()'), self.takeSnap())
def takeSnap(self):
#Grab the last active 3d viewport
mc.modelEditor('snapEditor', edit=True, activeView=True)
view = omUI.M3dView.active3dView()
#read the color buffer from the view, and save the MImage to disk
image = om.MImage()
view.readColorBuffer(image, True)
image.writeToFile('D:/snapShot.jpg', 'jpg')
def runUI():
global app
global win
app=QtGui.qApp
win = myUIClass()
win.show()
runUI()