maya lock脚本

#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)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值