asDouble() returns the first item added to the MScriptUtil, not the value of
the pointer. Your call to createFromDouble(0.0) is adding the value 0.0 to the
MScriptUtil, so when you call asDouble, it's returning that value. If you did
createFromDouble(10.0), and called asDouble(), you'd get all 10.0's back.
You want to use MScriptUtil.getDouble(), which takes a double pointer, and
returns it's value.
You also don't need to recreate the MScriptUtil or the pointer in each loop.
And as a final aside I've seen people use createFromDouble/List/Int/etc on the
MScriptUtil with 0 before casting it as a pointer, but it seems to work fine
without doing that. Can anyone chime in if/why that's necessary?
pFaceIterator = OpenMaya.MItMeshPolygon(inputGeometryObject)
faceAreas = []
faceArea = OpenMaya.MScriptUtil()
faceAreaPntr = faceArea.asDoublePtr()
while not pFaceIterator.isDone():
pFaceIterator.getArea(faceAreaPntr)
faceAreas.append(faceArea.getDouble(faceAreaPntr))
pFaceIterator.next()
On Thursday, March 14, 2013 10:59:45 AM UTC-7, Ethan Shilling wrote:
> Im trying to get the area of individual faces on a polygon object using the
> Maya Python API.
>
> I'm using the 'getArea' method in a 'MItMeshPolygon' iterator.
> It requires a pointer to a double variable to store the area value in. (so I
> figured 'MScriptUtil' is also needed)
> Although I don't get any errors, the 'getArea', just seems to be outputting
> 0.0 for all faces.
>
> So here is a snippet of code.
>
> pFaceIterator = OpenMaya.MItMeshPolygon(inputGeometryObject)
> faceAreas = []
> while not pFaceIterator.isDone():
> faceArea = OpenMaya.MScriptUtil()
> faceArea.createFromDouble(0.0) # also tried without this line
> faceAreaPntr = faceArea.asDoublePtr()
> pFaceIterator.getArea(faceAreaPntr) # this is what is not working
> properly
> faceAreas.append(faceArea.asDouble())
> pFaceIterator.next()
>
> Does anyone know why this is happening or know any fixes or alternate methods?
>
> Thanks
> Ethan
--
You received this message because you are subscribed to the Google Groups
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.