# ------------------------------------------------------------------------------ # gbZeroOut.py - Maya Python Script # ------------------------------------------------------------------------------ # # DESCRIPTION: # A simple script to zero out the selected object by parenting it under a group. # The name of the selected object is used to properly rename the group. # # USAGE: # (PYTHON) import gbZeroOut; gbZeroOut.zeroOut() # (MEL) python("import gbZeroOut;gbZeroOut.zeroOut()") # # AUTHOR: # Giorgio Bertolone - mail@giorgiobertolone.com - www.giorgiobertolone.com # Copyright (C)2010 Giorgio Bertolone - All Rights Reserved. # # VERSIONS: # 1.02 - Dec 28, 2010 - Changed suffix to Adj and cleaned some lines # 1.01 - Aug 03, 2008 - Added check for selection errors # 1.00 - Aug 01, 2008 - Initial Release # # ------------------------------------------------------------------------------ import maya.cmds as mc def zeroOut(): # check for selection errors sel = mc.ls( sl=True ) if len(sel) > 1: mc.confirmDialog( title="Selection Error", message="More than one object is selected. Please select only one.", button=["Ok"], defaultButton="Ok" ) if len(sel) < 1: mc.confirmDialog( title="Selection Error", message="Nothing is selected. Please select an object.", button=["Ok"], defaultButton="Ok" ) if len(sel) == 1: # create the group and name it properly suf = "Adj" csel = sel[0] ren = "%s+%s"%( csel, suf) adj = mc.group( sel, n=ren, em=True ) # center the pivot mc.xform( os=True, piv=(0, 0, 0) ) # create parent and scale constraints mc.parentConstraint( sel, adj, n="tempParentConstraint", w=1) mc.scaleConstraint( sel, adj, n="tempScaleConstraint", o= (1, 1, 1), w=1 ) # select and delete the constraints mc.delete( "tempParentConstraint", "tempScaleConstraint" ) # parent the object under the group mc.parent( sel, csel + "_Adj" ) # return to the object mc.select( sel )