pymel.core.general.objectCenter

objectCenter(*args, **kwargs)

This command returns the coordinates of the center of the bounding box of the specified object. If one coordinate only is specified, it will be returned as a float. If no coordinates are specified, an array of floats is returned, containing x, y, and z. If you specify multiple coordinates, only one will be returned.

Flags:

Long Name / Short Name Argument Types Properties
gl / gl bool ../../../_images/create.gif
  Return positional values in global coordinates (default).
local / l bool ../../../_images/create.gif
  Return positional values in local coordinates.
x / x bool ../../../_images/create.gif
  Return X value only
y / y bool ../../../_images/create.gif
  Return Y value only
z / z bool ../../../_images/create.gif
  Return Z value only Flag can have multiple arguments, passed either as a tuple or a list.

Derived from mel command maya.cmds.objectCenter

Example:

import pymel.core as pm

# create a simple hierarchy
pm.polyCube( name='a' )
# Result: [nt.Transform(u'a'), nt.PolyCube(u'polyCube1')] #
pm.polyCube( name='b' )
# Result: [nt.Transform(u'b'), nt.PolyCube(u'polyCube2')] #
pm.parent( 'b', 'a' )
# Result: [nt.Transform(u'b')] #
pm.move( 3, 0, 0, 'a', localSpace=True )
pm.move( 2, 2, 2, 'b', localSpace=True )

X_COORD = pm.objectCenter('b',x=True)

# Get the center of the bounding box of b in local space
XYZ = pm.objectCenter('b', l=True)

# Get the center of the bounding box of b in world space
XYZ = pm.objectCenter('b', gl=True)

# Get the center of the bounding box of a in world space
XYZ = pm.objectCenter('a', gl=True)