Code: Select all
import maya.api.OpenMaya as om
coordValue = om.MItMeshPolygon.center(om.MSpace.kWorld)
print(coordValue) #am expecting this to give me the center of the face I have selected
#Error: TypeError: descriptor 'center' for 'OpenMaya.MItMeshPolygon' objects doesn't apply to a 'int' object
import maya.api.OpenMaya as om
print(om.MSpace.kWorld) #prints 4
coordValue = om.MItMeshPolygon.center(4) #am expecting this to give me the center of the face I have selected
print(coordValue)
< /code>
Ich habe die DevKit -Beispiele durchgesehen, die Autodesk bietet, aber keine Antwort finden konnten. Was könnte ich falsch machen? Am auf Mai 2026. Na ja teilweise.import maya.api.OpenMaya as om
import maya.cmds as cmds
def get_selected_center():
selection = om.MGlobal.getActiveSelectionList()
if selection.length() == 0:
raise RuntimeError("Nothing selected")
dag_path, component = selection.getComponent(0)
if not dag_path.node().apiType() == om.MFn.kMesh:
raise RuntimeError("Selected object is not a mesh")
poly_iter = om.MItMeshPolygon(dag_path, component)
center = poly_iter.center(om.MSpace.kWorld)
return center
center = get_selected_center() # this retuns a three part array, well maybe not an array, but definetly something
cmds.spaceLocator(p=(center.x, center.y, center.z))
< /code>
Das einzige Problem ist, dass der obige Code nur so funktioniert, wie ich es erwarte, wenn ich ein Polygon -Gesicht ausgewählt habe. Mitte einer ausgewählten Kante, Gesicht oder an der Position eines Scheitelpunkts