Setting an attribute selected in Channel Box


#1

Hello! I am creating some simple scripts to zero out specific channels of items to help make animating faster and keep me from having to go to the channel box, highlight the attributes I want to zero out and then type zero and hitting enter.

I have one for rotations and translations, but wanted to create one for attributes that aren’t so common place on a rig. So basically I would like to highlight a channel or channels in the channel box and then apply my script which is currently setup in a marking menu.

Any ideas how to make this work? Or if you can think of something even better, I am open to ideas. Programmer I am not so I am completely open to suggestions.

The code I am using to do the zeroing out is this: (found this elsewhere on this site but it was for setting scale to a specific number so I modified it for just zeroing out the rotate values)

string $array[] = ls -sl;
for ($item in $array)
{
setAttr ($item + “.rotate”) 0 0 0;
}

Any help is greatly appreciated!


#2

You can use channelbox command (http://download.autodesk.com/us/maya/2011help/Commands/channelBox.html) and query : selectedMainAttributes, selectedShapeAttributes, selectedHistoryAttributes, selectedOutputAttributes


#3

DrWeeny, doesn’t the channelBox command actually create a channel box? I don’t need to create one, just change an existing attribute that is selected in the channel box.

Forgive me if I am not understanding your response as I am not a programmer!

*******Edit
Ok, so I found that the command I think I would need is:
channelBox -q -sma mainChannelBox

Still trying to figure out how to set it for the selected attribute. I will keep googling!

*******Edit 2
Ok, this is what I have so far. I am getting close! It still doesnt recognize the attribute.
If I do a print $attribute, it returns the attribute I have selected in the channel box, but in the script below I get an error that says, "// Error: line 5: setAttr: Invalid object name: [selectedObject].$attribute //, instead of $attribute being the selected attribute in the channel box.

$object = ls -sl;
$attribute = channelBox -q -sma mainChannelBox;
for ($item in $object)
{
setAttr ($item + “.$attribute”) 0;
}


#4

I think that putting “.$attribute” in quotes like that make Maya read it as is.

Try:

setAttr ($item + "." + $attribute) 0;

(Disclaimer: Its early and I can’t check/remember 100% right now :blush: )


#5

Thanks for the help, Faux but I got the following error when I tried it:
// Error: Line 5.34: Illegal operation “+” on data of type string[]. //


#6

Ahh, here Maya is telling you that $attribute is a string array but you didn’t give it an index position to work with.

Something like:

setAttr ($item + "." + $attribute[0]) 0;

Where [0] is the first item in the array.

You can make a for loop with a counter to increment through the array items every time the loop…err…loops.

Maybe this?

$object = `ls -sl`;

$attribute = `channelBox -q -sma mainChannelBox`;

for ($i=0; $i<size ($attribute); $i++ )
{
    setAttr ($item + "." + $attribute[$i]) 0;
}

#7

Got the following reply from CharlieWales over on CreativeCrash who solved the problem!
A great many thanks to him!! Hope someone else finds these little scripts useful!
And thanks to you too, Faux for helping out!!

//This only works fir the first selected attribute

string $object[] = ls -sl;
string $attribute[] = channelBox -q -sma mainChannelBox;
for ($item in $object)
{
setAttr ($item + “.” + $attribute[0]) 0;
}

//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////

//This works with every selected attribute

string $object[] = ls -sl;
string $attribute[] = channelBox -q -sma mainChannelBox;
for ($item in $object)
for($attr in $attribute)
setAttr ($item + “.” + $attr) 0;