#lockTemple
#################################################################################################
摆模板生成骨骼的时候经常存在父子关系在子层级摆好了再挪动父层级就会动到之前的模板位置,这时候需要锁定一下父层级,代码如下
#################################################################################################
import maya.cmds as mc
import string
if mc.window('LockWin',ex=1)==1:
mc.deleteUI('LockWin')
mc.window('LockWin',t="lockTemple",wh=(300,100))
mc.columnLayout(adj=1)
mc.button('LOCK_select',l="LK_select",c='LK_select()')
mc.button('unLOCK_select',l="unLK_select",c='UnLK_select()')
mc.button('unLK_All',l="unLK_All",c='unLK_all()')
mc.showWindow('LockWin')
def LK_select():
myNeedLock=mc.ls(sl=True)
myFinalAttr=[]
myChannel=['translateX','translateY','translateZ','rotateX','rotateY','rotateZ']
for a in range(len(myNeedLock)):
myNewLOC=mc.spaceLocator( p=( 0, 0 ,0),n=myNeedLock[a]+"_LOCKconstraint")
myNeedHaveAttr=mc.listAttr('pSphere1',k=1)
for b in myNeedHaveAttr:
if b in myChannel and mc.getAttr(myNeedLock[a]+'.'+b,l=1)==0 and mc.getAttr(myNeedLock[a]+'.'+b,k=1)==1:
myFinalAttr.append(b)
skipTranslate=[]
skipRotate=[]
if myFinalAttr!=[]:
for c in myChannel:
if c not in myFinalAttr:
if "translate" in c:
if c[-1] not in skipTranslate:
skipTranslate.append(c[-1])
elif "rotate" in c:
if c[-1] not in skipRotate:
skipRotate.append(c[-1])
skipTranslate= [item.lower() for item in skipTranslate]
skipRotate= [item.lower() for item in skipRotate]
mc.parentConstraint(myNewLOC[0],myNeedLock[a],mo=1,skipTranslate=skipTranslate,skipRotate=skipRotate,w=1)
def UnLK_select():
needUnLock=mc.ls(sl=True)
for a in needUnLock:
myCons=mc.listRelatives(a,type='parentConstraint')
if myCons:
mc.delete(myCons[0])
if mc.objExists(a+'_LOCKconstraint'):
mc.delete(a+'_LOCKconstraint')
def unLK_all():
myCNS_LOC=mc.select('*_LOCKconstraint')
allLoc=mc.ls(sl=True)
for a in allLoc:
myCons=mc.listConnections(a,s=0,d=1)
if myCons:
mc.delete(myCons[0])
mc.delete(a)