View Full Version : python API MFnMesh.getUvShellsIds buggy crash argh!
02-16-2011, 01:43 AM
My getUvShellsIds method crashes on running the code below.
Have a dagPath that points correctly a polygon plane.
I've tried using an MObject instead of a MDagPath, I've tried passing in the shape instead of the plane.
Crazily, I'm pretty sure this code does work every now and then... Then the next day it crashes again. Sigh. I really need a good way to get UV shells without doing any UI selection.
Create a new polygon plane, run the python code below:
name = 'pPlane1' # or pPlaneShape1, same result
selectionList = maya.OpenMaya.MSelectionList()
myMesh = maya.OpenMaya.MFnMesh(dagPath)
uvShellIDs = maya.OpenMaya.MIntArray()
numShells = maya.OpenMaya.MScriptUtil().asUintPtr()
Btw, Using maya 2011 64bit, on Windows 7.
I could be wrong, but could it be you need to initialize properly your MScriptUtil variable before passing it to the API?
I had some really weird behavior and crashes with a script of mine, it seems was caused by my not having properly initialized the MScriptUtils variables before sending them to the API.
specifically this part:
meshFn = maya.OpenMaya.MFnMesh(node)
u_util = maya.OpenMaya.MScriptUtil()
u_ptr = u_util.asFloatPtr()
v_util = maya.OpenMaya.MScriptUtil()
v_ptr = v_util.asFloatPtr()
meshFn.getUV(0, u_ptr, v_ptr)
u = u_util.getFloat(u_ptr)
v = v_util.getFloat(v_ptr))
you might have to properly create a int variable, initialize it to whichever value, then gets its pointer and pass it to the API.
02-17-2011, 01:24 AM
Sweet, yeah I think that did it! There's a chance it'll start crapping out again tomorrow, but looks good for now....
I should've tried that myself, but the pointer being a uInt confused me.
Mucho gracias good sir!
02-17-2011, 04:36 PM
In order to avoid the problems that arise when using MScriptUtil you could use PyMEL. It offers access to the API the Python way and is included in Maya 2011, just have a look at the docs.
02-17-2011, 04:36 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.