简体   繁体   中英

Maya + Python: Move pivot to bottom of bounding box

How can I move just the pivot of the selected node to the bottom of the bounding box?

# Move the pivot for each selected not to it's center then bottom

import maya.cmds as cmds

curSel = cmds.ls(long = True, selection = True, type = 'dagNode')

for n in curSel:
    bbox = cmds.exactWorldBoundingBox(n)

    cmds.xform(n, cp=1)

bbox is a 6-element list of XYZ min and XYZ max : [xmin, ymin, zmin, xmax, ymax, zmax] . If you want the pivot point to be the bottom center, you'll want the average X, minimum Y, and average Z:

bbox = cmds.exactWorldBoundingBox(n)
bottom = [(bbox[0] + bbox[3])/2, bbox[1], (bbox[2] + bbox[5])/2]
cmds.xform(n, piv=bottom, ws=True)

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM