#  ----------------------------------------------------------------------------------------------------------
#  gbShapeParent.py - Maya Python Script 
#  ----------------------------------------------------------------------------------------------------------
#
#  DESCRIPTION:
#  A script to shape parent the second selected object to the first selected object.
#  The name of the first selected object is used to properly rename the shapes.
#
#  USAGE:
#  (PYTHON)  import gbShapeParent; gbShapeParent.shapeParent()
#  (MEL)     python("import gbShapeParent;gbShapeParent.shapeParent()")
# 
#  AUTHOR:
#  Giorgio Bertolone - mail@giorgiobertolone.com - www.giorgiobertolone.com
#  Copyright (C)2008 Giorgio Bertolone - All Rights Reserved.
#
#  VERSIONS:
#  1.01 - Aug 12, 2008 - Fixed a bug when parenting objects with more than one shape node 
#  1.00 - Aug 11, 2008 - Initial Release
#  ----------------------------------------------------------------------------------------------------------


import maya.cmds as mc

def shapeParent():

# check for selection errors	
	sel = mc.ls( sl=True )
	if len(sel) > 2:
		mc.confirmDialog( title="Selection Error", message="More than two objects are selected. Please select only two.", button=["Ok"], defaultButton="Ok" )
	if len(sel) == 0:
		mc.confirmDialog( title="Selection Error", message="Nothing is selected. Please select two objects.", button=["Ok"], defaultButton="Ok" )
	
# parent the shape(s) to the object	
	sel = mc.ls( sl=True )
	mc.select( sel[1] )
	shapeList = mc.ls( sel[1], shapes=True, dag=True, ap=True, sl=True )
	mc.parent( sel[1], sel[0] )
	mc.select( sel[1] )
	mc.makeIdentity( apply=True, t=1, r=1, s=1, n=0 )
	mc.parent( w=True )
	mc.parent( shapeList, sel[0], r=True, s=True )
	mc.delete( sel[1] )
	mc.select( sel[0] )

# rename the shapes
	nameList = mc.ls( sel[0], shapes=True, dag=True, ap=True, sl=True )
	print nameList
	for x in nameList:
		mc.rename( x, sel[0] + "Shape_00" )
