#  ------------------------------------------------------------------------------------
#  gbLock.py - Maya Python Script 
#  ------------------------------------------------------------------------------------
#
#  DESCRIPTION:
#  This script locks and unlocks the attributes in your selection.
#  It works on translation, rotation, scale and visibility.
#
#  USAGE:
#  (PYTHON)  import gbLock; gbLock.unLock()
#  (MEL)     python("import gbLock;gbLock.unLock()")
#  (PYTHON)  import gbLock; gbLock.lock()
#  (MEL)     python("import gbLock;gbLock.lock()")
#
#  AUTHOR:
#  Giorgio Bertolone - mail@giorgiobertolone.com - www.giorgiobertolone.com
#  Copyright (C)2010- Giorgio Bertolone - All Rights Reserved.
#
#  VERSIONS:
#  1.00 - Dec 28, 2010 - Initial Release
#
#  ------------------------------------------------------------------------------------


import maya.cmds as mc

def unLock():

# check and warn if nothing is selected
	sel = mc.ls( sl=True, fl=True )
	if sel == []:
		mc.confirmDialog( title="Selection Error", message="Nothing is selected.", button=["Ok"], defaultButton="Ok" )

# for each selection unlock the translation, rotation, scale and visibility attributes
	for i in sel:
		mc.setAttr( '%s.tx' % i, lock=False, keyable=True )
		mc.setAttr( '%s.ty' % i, lock=False, keyable=True )
		mc.setAttr( '%s.tz' % i, lock=False, keyable=True )
		mc.setAttr( '%s.rx' % i, lock=False, keyable=True )
		mc.setAttr( '%s.ry' % i, lock=False, keyable=True )
		mc.setAttr( '%s.rz' % i, lock=False, keyable=True )
		mc.setAttr( '%s.sx' % i, lock=False, keyable=True )
		mc.setAttr( '%s.sy' % i, lock=False, keyable=True )
		mc.setAttr( '%s.sz' % i, lock=False, keyable=True )
		mc.setAttr( '%s.visibility' % i, lock=False, keyable=True )

def lock():

# check and warn if nothing is selected
	sel = mc.ls( sl=True, fl=True )
	if sel == []:
		mc.confirmDialog( title="Selection Error", message="Nothing is selected.", button=["Ok"], defaultButton="Ok" )

# for each selection lock and hide the translation, rotation, scale and visibility attributes and make them not keyable
	for i in sel:
		mc.setAttr( '%s.tx' % i, lock=True, keyable=False )
		mc.setAttr( '%s.ty' % i, lock=True, keyable=False )
		mc.setAttr( '%s.tz' % i, lock=True, keyable=False )
		mc.setAttr( '%s.rx' % i, lock=True, keyable=False )
		mc.setAttr( '%s.ry' % i, lock=True, keyable=False )
		mc.setAttr( '%s.rz' % i, lock=True, keyable=False )
		mc.setAttr( '%s.sx' % i, lock=True, keyable=False )
		mc.setAttr( '%s.sy' % i, lock=True, keyable=False )
		mc.setAttr( '%s.sz' % i, lock=True, keyable=False )
		mc.setAttr( '%s.visibility' % i, lock=True, keyable=False )