PDA

View Full Version : advice for using api stuff with python


aguirre
10-01-2010, 10:32 PM
hi!
iīm just trying to do my first steps using api classes;
- and i donīt get it

maybe somebody could give me some advice with this one:


import maya.OpenMaya as om

def pFaceArea(face):
om.MGlobal.clearSelectionList()
om.MGlobal.selectByName(face)
sList = om.MSelectionList()
om.MGlobal.getActiveSelectionList(sList)

dagPath = om.MDagPath()
component = om.MObject()

sList.getDagPath(0, dagPath)
polyIter = om.MItMeshPolygon(dagPath, component)

util = om.MScriptUtil()
util.createFromDouble(0.0)
ptr = util.asDoublePtr()
polyIter.getArea(ptr, om.MSpace.kWorld)
area = om.MScriptUtil(ptr).asDouble()

return(area)

mduvekot
10-02-2010, 11:12 PM
I don't understand what the problem is. That code works when I run it.

aguirre
10-03-2010, 09:10 AM
ok, sry i forgot to mention that it kind of works, but only on *.f[0]. so it doesnīt take the given face and always take f[0], what i donīt understand.

thanks

mduvekot
10-03-2010, 01:19 PM
pFaceArea('polySurface1.f[5] ')
# Result: 7.7774753570556641 #

is fine

aguirre
10-03-2010, 08:04 PM
hm, didnīt work for me - i did a test by looping faces of different size and it didnīt work.
anyway it works with this script - found a similar script at maya-station, and changed it at little

thanks for reply anyway,


import maya.OpenMaya as om

def pFaceArea(face):
om.MGlobal.clearSelectionList()
om.MGlobal.selectByName(face)
sList = om.MSelectionList()
om.MGlobal.getActiveSelectionList(sList)

sIter = om.MItSelectionList(sList, om.MFn.kMeshPolygonComponent) #change1

dagPath = om.MDagPath()
component = om.MObject()

sIter.getDagPath(dagPath, component) #change2
polyIter = om.MItMeshPolygon(dagPath, component)

util = om.MScriptUtil()
util.createFromDouble(0.0)
ptr = util.asDoublePtr()
polyIter.getArea(ptr, om.MSpace.kWorld)
area = om.MScriptUtil(ptr).asDouble()

return(area)

CGTalk Moderation
10-03-2010, 08:04 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.