import maya.OpenMaya as OM
import math

def faceCenter():
    faceCenter = []

    selection = OM.MSelectionList()
    OM.MGlobal.getActiveSelectionList(selection)
    print ("Number of objects in selection: %s " % selection.length())

    iter = OM.MItSelectionList(selection, OM.MFn.kMeshPolygonComponent)

    while not iter.isDone():
        dagPath = OM.MDagPath()
        component = OM.MObject()

        iter.getDagPath(dagPath, component)

        polyIter = OM.MItMeshPolygon(dagPath, component)

        while not polyIter.isDone():
            center = OM.MPoint
            center = polyIter.center(OM.MSpace.kWorld)
            
            #method A. (works fine)
            point = [center.x, center.y, center.z]
            faceCenter += point # <<< works fine

            #method B. (makes it run into an infinite loop / memory leak)
            #faceCenter += center

            polyIter.next()

        iter.next()

    return faceCenter

Hi there! First post!

Based upon some code that I've found (in this group) about looping over 
faces and getting their centers, I ran into the following problem. 
I've highlighted 2 methods in the polyIter section where I try to store the 
center as an MPoint. 

center is already an MPoint*, but apparently I'm not allowed to store the 
point directly into a list. Anybody who can point out why this is? Because 
it's an MPoint reference? 

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/a8d10aae-31a4-4134-b4c7-e28c593d205d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to