Got pointed to the blog post here by Rob Bredow. Take a gander.
As I figured, Maya actually does most the heavy lifting for you, if you know what to call. This blog post by Cyrille Fauvel describes another way to do it.
I've condensed those notes down into my own method here:
As I figured, Maya actually does most the heavy lifting for you, if you know what to call. This blog post by Cyrille Fauvel describes another way to do it.
I've condensed those notes down into my own method here:
import maya.cmds as mc import maya.OpenMaya as om import maya.OpenMayaUI as omui def getScreenSpace(node): """ Return the screen-space position of the node. 0,0 is the bottom left. +X goes to the right, +Y goes up. """ activeView = omui.M3dView.active3dView() # Can't use 'pointPosition', since that will return values in the 'ui units', # and we need them returned in 'internal units', which is what the matrix # attr stores: mtxList = mc.getAttr("%s.worldMatrix"%node) # Extract just the position: pt = om.MPoint(mtxList[12], mtxList[13], mtxList[14]) # Pointer hoop-jumping... xPtrInit = om.MScriptUtil() yPtrInit = om.MScriptUtil() xPtr = xPtrInit.asShortPtr() yPtr = yPtrInit.asShortPtr() activeView.worldToView(pt, xPtr, yPtr) x = xPtrInit.getShort(xPtr) y = yPtrInit.getShort(yPtr) return x,yDocs for OpenMayaUI's M3dView