View Full Version : MPxContext issues (Python API)

03 March 2011, 02:23 PM
Hi there. Here are a couple of problems I cannot solve until now and since time doesn't seem to slow down I would be very gratefull for some help :)

First of all it's all about Python API aka scripted plugins. I'm trying to make a tool, similar to the "draw curve" tool, which comes in maya.
My first problem is getting the right 3D coordinates from the MEvent.getPosition(), so they are lying on the construction plane. Here a snippet which is supossed to create a locator at (0,0,0), or whatever position you set for "sp":

import maya.OpenMaya as om
import maya.OpenMayaUI as omui
import maya.cmds as mc
m3dview = omui.M3dView.active3dView()
pts = om.MPointArray()
msx = om.MScriptUtil()
msy = om.MScriptUtil()
xptr = msx.asShortPtr()
yptr = msy.asShortPtr()
sp = om.MPoint(0,0,0)
wp = om.MPoint(sp)
wv = om.MVector()
m3dview.worldToView(wp, xptr, yptr)
x = msx.getShort(xptr)
y = msy.getShort(yptr)
m3dview.viewToWorld(x,y, wp, wv)
print x, y
parr = [wp[i] for i in range(3)]
varr = [wv[i] for i in range(3)]
print "#", [sp[i] for i in range(3)]
print "# P", parr
print "# V", varr
mc.move(parr[0], parr[1], parr[2])

One question following from this one is How to snap to a live surface? My buest guess so far is with MItSelectionList over the liveList and some MFnMesh.closestIntersection() ( calls.

Next thing is considering the GL calls. I can't make this work under CentOS and nVidia, but I'm pretty sure it works at home on my Win7 with GF 7600

import maya.OpenMaya as om
import maya.OpenMayaUI as omui
import maya.OpenMayaRender as omr
glRenderer = omr.MHardwareRenderer.theRenderer()
glFT = glRenderer.glFunctionTable()
dag = om.MDagPath()
m3dview = omui.M3dView.active3dView()
# Just to check the view
print dag.fullPathName()
m3dview.drawText("TEXXXXT", om.MPoint(0,0,0))

Last thing is how can you cal the _setCursor() from a python MPxContext? just translating the C++ call gives an error:

class Tool(ompx.MPxContext):
def __init__(self):

def doPress(self, event):
# C++ call:
#setCursor( MCursor::doubleCrossHairCursor );

// Error: TypeError: file /.../_api_rnd_/ line 21: in method 'MPxContext__setCursor', argument 2 of type 'MCursor const &' //

04 April 2011, 09:00 AM
First part solved....

CGTalk Moderation
04 April 2011, 09:00 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.