View Full Version : reset rig

09 September 2010, 08:58 PM
Hi guys.
Let me first apologize for my lack of knowledge.
I'm completere green when it comes to scripting but I really need to make a button that can reset my rig.
I'm gonna make a few buttons for selecting and keying all the controls which is easy enough, but now I want to be able to reset the rig into default pose.

I thought I could just use the selection I already know how to do, and use the selection to set the rotate and translate values to zero on all controls at the same time, without hard coding the names individually.
I did a quick test and thought this would do the trick:

string $selection[] = `ls -sl`;
setAttr "$selection[].rx" 0;
setAttr "$selection[].ry" 0;
setAttr "$selection[].rz" 0;

No such luck.
I get a
"// Error: string $selection[] = `ls -sl`;
// Error: Invalid redeclaration of variable "$selection" as a different type. // "

Can someone lead me in the right direction?
How do I set the rotational and translational values across a number of selected controls?

Cheers :)

09 September 2010, 09:36 PM
Yea, that error is annoying! But it's fairly clear, you're trying to change a variables type. Try keeping the code enclosed in brackets.

If it's just rotate & translate, this would work. But it's not very robust!

string $selection[] = `ls -sl`;

for($eachObj in $selection)
setAttr ($eachObj + ".rotate") 0 0 0;
setAttr ($eachObj + ".translate") 0 0 0;

09 September 2010, 06:08 PM
Hi :)
Thanks a lot for your reply.
The code works, but not if one of the selected objects has either of the channels locked unfortunately :/

Maybe I will just key the default pose at -1 and revert back to that whenever I need.
It would be cool with a shelf button though.
Maybe the attributes from the default pose could be read somehow and then called upon when through MEL?

I dunno, I just shoot blind here. Thought it was a common thing to have in a rig?

09 September 2010, 11:34 AM
Why not include A line to unlock channels first?

09 September 2010, 01:55 PM
this is what I use, works for all custom attributes as well as translates, rotates, etc...

string $sel[] = `ls -sl`;
for ($c in $sel) {
string $attrs[] = `listAttr -k $c`;
for ($c2 in $attrs) {
if (`getAttr -lock ($c + "." + $c2)` == 0) {
float $default[] = `attributeQuery -node $c -listDefault $c2`;
setAttr ($c + "." + $c2) $default[0];

09 September 2010, 06:13 PM
Wow, this works great!
Thank you so much :)

I even think I understand the code :)

CGTalk Moderation
09 September 2010, 06:13 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.