# ------------------------------------------------------------------------------ # 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)2008 Giorgio Bertolone - All Rights Reserved. # # VERSIONS: # 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 = "ZeroOut" csel = sel[0] ren = "%s+%s"%( csel, suf) mc.group( sel, n=ren, em=True ) # center the pivot mc.xform( os=True, piv=(0, 0, 0) ) # create parent and scale constraints mc.select( sel, af=True) mc.parentConstraint( n="tempParentConstraint", w=1) mc.scaleConstraint( n="tempScaleConstraint", o= (1, 1, 1), w=1 ) # select and delete the constraints mc.select( "tempParentConstraint", "tempScaleConstraint" ) mc.delete() # parent the object under the group mc.select( sel, csel + "_ZeroOut") mc.parent() # return to the object mc.select( sel )