Is there a Mel or Python command that returns the average position of the currently selected objects and/or components? I know that in component selection mode, selecting a set of vertices will cause the manipulator context to move to accommodate the selected vertices, but this does not seem to work in object mode.
In either case, my goal is to be able to easily obtain the average translation of the selected objects/components without having to write code specific to each sort of thing that may be selected.
you could try getting the world space position of all of the objects and then averaging it yourself - maybe something like this?
import maya.cmds as mc
sel = mc.ls(sl=True, fl=True)
count = len(sel)
sums = [0,0,0]
for item in sel:
pos = mc.xform(item, q=true, t=True)
sums[0] += pos[0]
sums[1] += pos[1]
sums[2] += pos[2]
center = [sums[0]/count, sums[1]/count, sums[2]/count]
*Note: edited based on some comments below
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.