Skip to content

Instantly share code, notes, and snippets.

@SEVEZ
Created August 29, 2015 11:18
Show Gist options
  • Save SEVEZ/d4ccef5562281e33d4eb to your computer and use it in GitHub Desktop.
Save SEVEZ/d4ccef5562281e33d4eb to your computer and use it in GitHub Desktop.
Copy pivot from second object to first object
'''
Align pivots by Serge Scherbakov.
Usage:
1. Select source object(s)
2. Add to selection target object
3. Run script by 'import copyPivot\n copyPivot.copyPivot()
'''
import maya.cmds as cmds
import maya.mel as mel
def copyPivot ():
sourceObj = cmds.ls(sl = True)[len(cmds.ls(sl = True))-1]
targetObj = cmds.ls(sl = True)[0:(len(cmds.ls(sl = True))-1)]
parentList = []
for obj in targetObj:
if cmds.listRelatives( obj, parent = True):
parentList.append(cmds.listRelatives( obj, parent = True)[0])
else:
parentList.append('')
if len(cmds.ls(sl = True))<2:
cmds.error('select 2 or more objects.')
pivotTranslate = cmds.xform (sourceObj, q = True, ws = True, rotatePivot = True)
cmds.parent(targetObj, sourceObj)
cmds.makeIdentity(targetObj, a = True, t = True, r = True, s = True)
cmds.xform (targetObj, ws = True, pivots = pivotTranslate)
for ind in range(len(targetObj)):
if parentList[ind] != '' :
cmds.parent(targetObj[ind], parentList[ind])
else:
cmds.parent(targetObj[ind], world = True)
copyPivot()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment