#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),menuBar=True)
mc.menu('about..')
mc.menuItem('author : 栋栋')
mc.menuItem('qq : 27971533')
mc.menuItem(d=1)
mc.menuItem('功能:摆模板时候锁定子层级,移动父层级')
mc.columnLayout(adj=1)
mc.button('LOCK_select',l="LOCK_select",bgc=(0.8,0.2,0.2),c='LK_select()')
mc.button('unLOCK_select',l="unLOCK_select",bgc=(0.8,.8,0.2),c='UnLK_select()')
mc.button('unLK_All',l="unLOCK_All",bgc=(0.2,0.2,0.2),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(myNeedLock[a],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)
欢迎交流 VX:27971533