Hi,
I'm not very au fait with the api or python for that matter, but I needed to get the face area of some polys and one of our tools coders wrote me a little plugin in the c++ api to get the result I needed.
So in an effort for me to start learning the api with a solid but simple example I took his source code and started trying to get it working through the python access to the maya api.
The problem I can't seem to get round is an error thrown when actually calling the getArea() function, it says the the parameters are wrong. I assume it's down to supplying the space(kWorld) and can't get it to work.
Any advice form python api coders or api coders in general who might have a tip for me would be appreciated. Thank you
Here is the function as I have it at the moment. the plugin loads and executes, but throws an error.
// Error: in method 'MItMeshPolygon_getArea', argument 2 of type 'double &'
# Traceback (most recent call last):
# File "C:/Documents and Settings/user/My Documents/maya/2008/scripts/getPolyArea.py", line 42, in doIt
# area = pIter.getArea(area, kWorld) #Here is the problem
# TypeError: in method 'MItMeshPolygon_getArea', argument 2 of type 'double &' //
the proc:
[codebox]def doIt(self,argList):
print "doIt.."
dagPath = OpenMaya.MDagPath()
#myObj = OpenMaya.MItMeshPolygon(dagPath)
sList = OpenMaya.MSelectionList()
OpenMaya.MGlobal.getActiveSelectionList(sList)
iter = OpenMaya.MItSelectionList(sList)
if(not iter.hasComponents()):
return OpenMaya.MStatus(kSuccess)
sList.getDagPath(0, dagPath)
kWorld = OpenMaya.MSpace.kWorld
totalArea = 0.0
while not iter.isDone():
item = OpenMaya.MDagPath()
component = OpenMaya.MObject()
iter.getDagPath(item, component)
status = OpenMaya.MStatus()
pIter = OpenMaya.MItMeshPolygon(item, component);
area = 0.0
while not pIter.isDone():
#print "well we got here at least"
area = pIter.getArea(area, kWorld) #Here is the problem
totalArea += area
pIter.next()
iter.next()
OpenMaya.setResult(totalArea)
return OpenMaya.MStatus.kSuccess [/codebox]