############################################################################# ## lockSkinWeights.py v1.1 by Andrew Osiow (c) 2009 ## ## Gui for Locking or Unlocking all the Skin Weights of a selected meshes or ## joint chains. ## ## v1.1 has been modified to be run from the script editor or as a stand ## alone program. ## It only trys to update the Tool Settings window if the Paint Weights ## tool is active. ## ## To be used freely with the author's permission. Please contact the author ## if you wish upload or post this script to another site. ## ## usage: import lockSkinWeights.py ## lockSkinWeights.lockSkinWeights() ## Note: has to be in the Python Path to be imported corrected ## ## You can also run it from the Script Editor or drag it ## from the Script Editor to the Shelf. ## ############################################################################# import maya.cmds as cmds import maya.mel as mel def lockSkinWeights(): # import command used to allow script to run from script editor mel.eval( 'python("import lockSkinWeights");' ) # create interface # delete any old myEasyButtons window preferences if cmds.windowPref( 'lockSkinWeightsWindow', exists=True ): cmds.windowPref( 'lockSkinWeightsWindow', remove=True ) # delete any old myEasyButtons window structures if cmds.window( 'lockSkinWeightsWindow', exists=True ): cmds.deleteUI( 'lockSkinWeightsWindow', window=True ) # create a window structure lockSkinWeightsWin = cmds.window( 'lockSkinWeightsWindow', title='Skin Weights 1.1', rtf=1, s=0) # create my easy buttons layout lockSkinWeightsForm = cmds.columnLayout( w=150, h=78) # add gui buttons cmds.button( 'lockButton', width=150, height=26, label='Lock', align='center', command = 'lockSkinWeights.lockNodeWeights(1)' ) cmds.button( 'unLockButton', width=150, height=26, label='Unlock', align='center', command = 'lockSkinWeights.lockNodeWeights(0)' ) cmds.button( 'toggleButton', width=150, height=26, label='Toggle', align='center', command = 'lockSkinWeights.lockNodeWeights(-1)' ) # display lock buttons Window cmds.showWindow (lockSkinWeightsWin) #end def lockNodeWeights(lock): selectionList = cmds.ls( sl=True ) for item in selectionList: if cmds.nodeType ( item)[0] == 'joint': lockBoneWeight(item,lock) else: lockMeshWeights(item,lock) if cmds.currentCtx()=='artAttrSkinContext': cmds.setToolTo( 'selectSuperContext' ) cmds.setToolTo( 'artAttrSkinContext' ) #end def lockMeshWeights(mesh,lock): shapeNode = cmds.listRelatives( mesh, s=True )[0] skinClusterNode = cmds.listConnections( shapeNode, s=True, type='skinCluster' )[0] jointList = cmds.listConnections( skinClusterNode, s=True, type='joint' ) tempDict = {}.fromkeys(jointList) uniqueList = tempDict.keys() for joint in uniqueList: if lock == -1: lockValue = cmds.getAttr( joint+'.liw' ) cmds.setAttr( joint+'.liw', 1 - lockValue ) if 1-lockValue: print joint + ' is locked.' else: print joint + ' is unlocked.' else: cmds.setAttr( joint+'.liw', lock ) if lock: print joint + ' is locked.' else: print joint + ' is unlocked.' #end def lockBoneWeight(currentJoint, lock): descendingJoints = cmds.listRelatives( currentJoint, c=True, type='joint' ) if descendingJoints: for nextJoint in descendingJoints: lockBoneWeight( nextJoint, lock ) cmds.setAttr( currentJoint+'.liw', lock ) if (lock): print currentJoint+' is locked.' else: print currentJoint+' is unlocked.' #end # command to initate script from script editor lockSkinWeights()