How could I switch particular object's channel lock or unlock with mel?

How could I switch particular object's channel lock or unlock with mel?

openflier
Participant Participant
2,313 Views
10 Replies
Message 1 of 11

How could I switch particular object's channel lock or unlock with mel?

openflier
Participant
Participant

Is there any way to realize this function?I got a feet control,there is a custom channel to control bare feet or not,but I need automatic to control another custom channel to switch lock or unlock when I switch bare feet or not.Just in case animator confuse which channel can do it.

Is there anyone could show me how to solve it with mel or python?THX

Accepted solutions (2)
2,314 Views
10 Replies
Replies (10)
Message 2 of 11

mcw0
Advisor
Advisor

"setAttr -lock 0" to unlock

"setAttr -lock 1" to lock

0 Likes
Message 3 of 11

openflier
Participant
Participant

Thank U but I really want is like,I got another switch control,the control have a custom attribute call"bare foot",it's a boolean type.So,what if the code like this:

if cc_footSwitch.bareFoot = 1

        set cc_leftFoot.heel.Attr -lock 0

else        

        set cc_leftFoot.heel.Attr -lock 1;

 

I don't know if U can read it,but which I know is this code will not gonna work,cuz I don't do code...plz don't lagh at me.

0 Likes
Message 4 of 11

mcw0
Advisor
Advisor

We are all learning so no laughing allowed.  🙂

 

Check out "scriptJob".  It can do things when certain things happen.  Such as switching to barefeet.  

 

global proc barefeetSwitch()

{

    setAttr cc_leftFoot.heel.Attr -lock (1 - cc_footSwitch.bareFoot);

}

 

scriptJob -kws -attributeChange "cc_footSwitch.bareFoot" barefeetSwitch;

 

Copy and paste that into your scriptEditor window and test it.  If it's what you want, then you will want this to automatically happen when you open your file.  To do that, you have to create a script node.  I don't have Maya open so you can google "script node in Maya".   But it's the first tab in the expression editor.  Select the one for "script node".  Then paste the above code to create a new script node.  Then set this to happen before GUI open.  I hope that makes sense.

0 Likes
Message 5 of 11

openflier
Participant
Participant

//I changed it with some new names,I successful run it,but nothing happened,the code like this:


global proc cc_configNeka()

{

setAttr cc_leftFootHeel.rotateX -lock (1 - cc_configNeka.bareFeet);

}

 

scriptJob -kws -attributeChange "cc_configNeka.bareFoot" barefeetSwitch;

 

//I do some research about"scriptJob"doing,but can't really understand what it says.And the "cc_configNeka" is the name of the switch controller name,the attribute is like"cc_configNeka.BareFeet",the value of "BareFeet"is"on/off"(not 0to1);And the channel which I wanna block/unblock is "cc_rightFootHeel.rotateX",so I change the name of Ur code,and run it successful,but nothing happened,the channel I wanna block is still open to keyable.

Message 6 of 11

mcw0
Advisor
Advisor

Ah, ok.  So your "barefeet" attribute is an enum with values of "on:off".  My example was expecting "0:1".  I'm adding a print statement so that you can get some feedback.

 

global proc cc_configNeka()

{

    int $lock = `getAttr cc_configNeka.bareFeet`;

    print ("LOCK: "+$lock+"\n");

    setAttr cc_leftFootHeel.rotateX -lock $lock;

}

 

scriptJob -kws -attributeChange "cc_configNeka.bareFoot" cc_configNeka;

0 Likes
Message 7 of 11

openflier
Participant
Participant

After I renew those names,I got the correct return string,but nothing else happened.The target channel-"cc_rightBareFootHeel.rotateX"still remain keyable.Code I have renew like:

global proc cc_configNeka()

{

int $lock = `getAttr cc_configNeka.BareFeet`;

print ("LOCK: "+$lock+"\n");

setAttr cc_leftFootHeel.rotateX -lock $lock;

}

 

scriptJob -kws -attributeChange "cc_configNeka.BareFeet" cc_configNeka;

I got another issue to fix last few days,sorry to reply this late.And in order to solve this problem easily,I decided to  uploaded my .mb file.For the record,this file is for exercise,just wanna to improve my rigging sill.

0 Likes
Message 8 of 11

mcw0
Advisor
Advisor
Accepted solution

global proc cc_configNeka()
{
        int $lock = `getAttr cc_configNeka.BareFeet`;

        print ("LOCK: "+$lock+"\n");

        setAttr -lock $lock cc_rightBareFootHeel.rotateX;
        setAttr -k (1-$lock) cc_rightBareFootHeel.rotateX;
}

scriptJob -kws -attributeChange "cc_configNeka.BareFeet" cc_configNeka;

0 Likes
Message 9 of 11

openflier
Participant
Participant

Thank U for Ur patience,but the result of this code is not work as respect,actually it's opposite.

Message 10 of 11

mcw0
Advisor
Advisor
Accepted solution

Sorry I must have understood the order of your enum incorrectly.  Just reverse the value of $lock.  I think this should do it.

 

        setAttr -lock (1-$lock) cc_rightBareFootHeel.rotateX;
        setAttr -k $lock cc_rightBareFootHeel.rotateX;

Message 11 of 11

openflier
Participant
Participant

It's work!Thank U!!!   😄