getFaceVertexNormal (Python API)

I’m trying to aligning objects on faces of other geometry.
I’ve got a succesfull raycast with position and face id.
But I’ve problems while getting the normal of the face…
I’m a starter, so any help is more than welcome!

import maya.cmds as cmds
import maya.OpenMaya as om

def getNormalFromFace(mesh, index):
    om.MGlobal.clearSelectionList()
    om.MGlobal.selectByName(mesh)
    sList = om.MSelectionList()
    om.MGlobal.getActiveSelectionList(sList)
    item = om.MDagPath()
    sList.getDagPath(0, item)
    item.extendToShape()
    fnMesh = om.MFnMesh(item)
    
    normal=om.MVector(0.0,0.0,0.0)
    try:
        fnMesh.getFaceVertexNormal(index,0,normal, om.MSpace.kWorld)
    except:
        print('error while processing getFaceVertexNormal')
    print('normal : [%s,%s,%s]' % (normal.x,normal.y,normal.z))

#create test setup
cmds.file(force=True, new=True)
mesh = cmds.polySphere(radius=10)[0]
getNormalFromFace(mesh,0) #maya crashes if I use any other value than 0

do you get the same problem with fnMesh.getPolygonNormal instead of fnMesh.getFaceVertexNormal?

[QUOTE=Theodox;18628]do you get the same problem with fnMesh.getPolygonNormal instead of fnMesh.getFaceVertexNormal?[/QUOTE]

Seems like this works, thanks!