PDA

View Full Version : Calling viewToWorld from Python crashes Maya


wdavidlewis
09-11-2009, 06:41 PM
I'm trying to write my first context plugin and I decided to try Python rather than C++.

In the doPress() method, I'm getting the screen coordinates of the mouse click and then calling viewToWorld(). When I do so, Maya hard crashes (i.e. it just goes away). Here's the code: argX = OpenMaya.MScriptUtil()
argX.createFromInt(0)
argXPtr = argX.asShortPtr()
argY = OpenMaya.MScriptUtil()
argY.createFromInt(0)
argYPtr = argY.asShortPtr()
event.getPosition(argXPtr, argYPtr)
sx = OpenMaya.MScriptUtil(argXPtr).asShort()
sy = OpenMaya.MScriptUtil(argYPtr).asShort()
print "pos = (" + str(sx) + ", " + str(sy) + ")\n"

originPt = OpenMaya.MPoint()
vec = OpenMaya.MVector()
nearClip = OpenMaya.MPoint()
farClip = OpenMaya.MPoint()
OpenMayaUI.M3dView().viewToWorld(sx, sy, nearClip, farClip)
Nothing tricky here. If I comment out viewToWorld() call, no crash.

I've tried both the nearClip/farClip version and the point/vector version. Both just crash. The screen coords I'm getting are correct. Though I have also tried just passing in (50, 50) and that crashes too.

Any ideas?

Thanks!

--- David

meuH
09-11-2009, 08:22 PM
I could be wrong, but I think you are missing a step before actually calling viewToWorld.

I am using the same method for a python script of mine and it is working fine with doing this:

maya3DViewHandle = omui.M3dView()
activeView = maya3DViewHandle.active3dView()
...
activeView.viewToWorld(...)

wdavidlewis
09-11-2009, 08:55 PM
You are correct. That seems to work.

Thanks!

--- David

CGTalk Moderation
09-11-2009, 08:55 PM
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.