Created
May 24, 2018 17:01
-
-
Save paulwinex/7cd495e6138e334f7b1bd8d6de1d872f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PySide.QtGui import * | |
from PySide.QtCore import * | |
from shiboken import wrapInstance as wrp | |
qApp = QApplication.instance() | |
geo = qApp.desktop().screenGeometry() | |
#xRes = geo.width() | |
yRes = geo.height() | |
def getScreenPos(dagPath): | |
nx, ny = getScreenSpace(dagPath.inclusiveMatrix()) | |
#nx, ny = getScreenSpace(dagPath.inclusiveMatrixInverse()) | |
ofsx, ofsy = getViewportPos() | |
x = nx + ofsx | |
y = yRes -(ny - ofsy)# + 30 | |
return x, y | |
def getScreenSpace(mat): | |
pt = om.MPoint(mat(3,0),mat(3,1),mat(3,2)) | |
xPtrInit = om.MScriptUtil() | |
yPtrInit = om.MScriptUtil() | |
xPtr = xPtrInit.asShortPtr() | |
yPtr = yPtrInit.asShortPtr() | |
OpenMayaUI.M3dView.active3dView().worldToView(pt, xPtr, yPtr) | |
x = xPtrInit.getShort(xPtr) | |
y = yPtrInit.getShort(yPtr) | |
#print x, y | |
return x,y | |
def selectMe(dagPath, v): | |
x,y = getScreenPos(dagPath) | |
if not v: | |
option.hideOpt() | |
else: | |
objName = om.MFnDependencyNode(dagPath.transform()).name() | |
option.showOpt(x, y, objName) | |
def moveUI(dagPath): | |
#x,y = getScreenPos(dagPath) | |
pos = getWindowPos(dagPath) | |
if pos: | |
option.updatePos(pos[0], pos[1]) | |
option.show() | |
else: | |
option.hideOpt() | |
def getWindowPos(dagpath): | |
#position node | |
mat = dagpath.inclusiveMatrix() | |
pt = om.MPoint(mat(3,0),mat(3,1),mat(3,2)) | |
#objectPos | |
xPtrInit = om.MScriptUtil() | |
yPtrInit = om.MScriptUtil() | |
xPtr = xPtrInit.asShortPtr() | |
yPtr = yPtrInit.asShortPtr() | |
OpenMayaUI.M3dView.active3dView().worldToView(pt, xPtr, yPtr) | |
xObj = xPtrInit.getShort(xPtr) | |
yObj = yPtrInit.getShort(yPtr) | |
#viewportsize | |
xPt = om.MScriptUtil() | |
wPt = om.MScriptUtil() | |
hPt = om.MScriptUtil() | |
x = xPt.asUintPtr() | |
w = wPt.asUintPtr() | |
h = hPt.asUintPtr() | |
OpenMayaUI.M3dView.active3dView().viewport(x, x, w, h) | |
wView, hView = wPt.getUint(w), hPt.getUint(h) | |
#Hide if off screen | |
if 0 > xObj or wView < xObj or 0 > yObj or hView < yObj: | |
return None | |
#viewport position from corner | |
xPt = om.MScriptUtil() | |
yPt = om.MScriptUtil() | |
x = xPt.asIntPtr() | |
y = yPt.asIntPtr() | |
OpenMayaUI.M3dView.active3dView().getScreenPosition(x, y) | |
xView, yView = xPt.getInt(x), yPt.getInt(y) | |
x = xView + xObj | |
y = hView - yObj + yView | |
return [x, y] | |
ptr = OpenMayaUI.M3dView.active3dView().widget() | |
viewWidget = wrp(long(ptr), QWidget) | |
def getWindowPosQt(dagpath): | |
#position node | |
mat = dagpath.inclusiveMatrix() | |
pt = om.MPoint(mat(3,0),mat(3,1),mat(3,2)) | |
xPtrInit = om.MScriptUtil() | |
yPtrInit = om.MScriptUtil() | |
xPtr = xPtrInit.asShortPtr() | |
yPtr = yPtrInit.asShortPtr() | |
OpenMayaUI.M3dView.active3dView().worldToView(pt, xPtr, yPtr) | |
#xObj = xPtrInit.getShort(xPtr) | |
#yObj = yPtrInit.getShort(yPtr) | |
qPt = QPoint(xPtrInit.getShort(xPtr),yPtrInit.getShort(yPtr)) | |
#print viewWidget.window().rect(), viewWidget.rect() | |
m = viewWidget.mapTo(viewWidget.window(), qPt) | |
vX = m.x() | |
vY = m.y() | |
#print vX, vY | |
return [vX, 1080 - vY] | |
def getViewportPos(): | |
xPt = om.MScriptUtil() | |
yPt = om.MScriptUtil() | |
x = xPt.asIntPtr() | |
y = yPt.asIntPtr() | |
OpenMayaUI.M3dView.active3dView().getScreenPosition(x, y) | |
return xPt.getInt(x), yPt.getInt(y) | |
#qApp = QApplication.instance() | |
#geo = qApp.desktop().screenGeometry() | |
#xRes = geo.width() | |
#yRes = geo.height() | |
def getMayaWindow(): | |
ptr = OpenMayaUI.MQtUtil.mainWindow() | |
if ptr is not None: | |
return wrp(long(ptr), QMainWindow) | |
qMayaWindow = getMayaWindow() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment