Mel script for locking selected attributes

Mel script for locking selected attributes

ekiep
Community Visitor Community Visitor
1,286 Views
2 Replies
Message 1 of 3

Mel script for locking selected attributes

ekiep
Community Visitor
Community Visitor

Hi, so I'm trying to write a simple script that allows me to just execute the "lock and hide" function to all selected attributes without me having to go through the menus. 

Here's is my frankenscript. I'm not very familiar with mel at all so I'm not sure what the syntax or anything is supposed to look like. This is just copy and pasted with some adjustments.

 

string $array[] = `ls -sl`;
for ($item in $array)
{
setAttr ($item -lock true -keyable false -channelBox false);
}

0 Likes
1,287 Views
2 Replies
Replies (2)
Message 2 of 3

Kahylan
Advisor
Advisor

Hi!

 

Your Frankenscript actually wasn't too far off. But to use the setAttr command you need to give it a specific Attribute. "pCube1.translateX" for example, while your script was just giving it the object, i.e  "pCube1".

 

The script you want looks like this:

string $sel[] = `ls -sl`;
string $selCBAttr[] = `selectedChannelBoxAttributes`;

for ($s in $sel){
for ($attr in $selCBAttr){
string $a = $s + "." + $attr;
setAttr -l off -k off -channelBox off $a;
}
}

It gets all the selected objects and all the selected attributes in the ChannelBox and then loops through both to create specific attributes.

 

Honestly, I think you'd still be faster by just using the RMB Dropdown Menu on the channelbox, since you still have to manually select the attributes. But that might be a matter of taste.^^

 

I hope this helps!

0 Likes
Message 3 of 3

Kahylan
Advisor
Advisor

If you truly want to be faster doing this than using a Menu I would suggest you create multiple small scripts that lock translates, rotates and scales. This way you don't have to select them in the channelbox first but just click the corresponding shelfbutton.

 

locking translates would look like this:

string $sel[] = `ls -sl`;
string $attributes[] = {"tx","tz","ty"};

for ($s in $sel){
for ($attr in $attributes){
string $a = $s + "." + $attr;
setAttr -l off -k off -channelBox off $a;
}
}

rotate and scale is just a matter of changing the strings in the $attributes array.

 

Have a nice day!

0 Likes