get area of mesh face

get area of mesh face

bmagner888
Enthusiast Enthusiast
816 Views
2 Replies
Message 1 of 3

get area of mesh face

bmagner888
Enthusiast
Enthusiast

How do I get the (worldspace units) of the area of any given mesh face?  Looking for a python solution.

most faces are not rectilinear and might contain any number of edges, so getting the attaced verts and doing some sort of spatial calculation is a nightmarish idea.

 

OpenMaya.MItMeshPolygon has a getArea() function but I can't figure out how to jump through all the hoops to actually use it, because  OpenMaya makes you recast everything through a hundred different class instances just to do simple things.  And the documentation isn't very helpful.

 

def get_face_area( 'polySurface1.f[0]'):
    area =?????????????????????
    return area

Thanks for any help.

0 Likes
Accepted solutions (1)
817 Views
2 Replies
Replies (2)
Message 2 of 3

jmreinhart
Advisor
Advisor
Accepted solution

 

 

import maya.api.OpenMaya as om2

def getMeshFaceArea(meshFace):
    # Get the mesh object as a dagPath
    selectionList = om2.MSelectionList()
    selectionList.add(meshFace)
    dagPath, component = selectionList.getComponent(0)
    
    # Create a polygon iterator
    meshIt = om2.MItMeshPolygon(dagPath,component)

    return meshIt.getArea(om.MSpace.kWorld)

Is there something specific about the documentation that you found difficult? I know I struggled when getting started with the API, so I'm happy to answer any questions.

 

0 Likes
Message 3 of 3

bmagner888
Enthusiast
Enthusiast

this is perfect.  thank you.

-b

0 Likes