PDA

View Full Version : how to get what attribute is selected in channel box on right


DEVILSAN
11-05-2011, 01:29 PM
Hi

I want to build my own toggle switch for lock selected and key slected or unlock , to do that i just simply want to click a button to toggle in shelf so that if i select any attribute of the object i should be able to lock or unlock just with a click rather than doing right cliock and lock selected..please help...

NaughtyNathan
11-05-2011, 07:56 PM
MEL? or python?
This has come up and been answered several times already on this forum, did you try a search? either way, you can do it in MEL like so:
string $selCBAttr[] = `selectedChannelBoxAttributes`;:nathaN

DEVILSAN
11-06-2011, 07:59 AM
I hate this but what i hav forget in concatinating



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

string $selCBAttr[] = `selectedChannelBoxAttributes`;

string $newStr = $selection +"."+ $selCBAttr;

print $newStr;

djx
11-06-2011, 10:39 AM
$selection and $selCBAttr are arrays, so you can not use them like that in a string. Since there may be more than one object and channel selected you need to do something like loop through them.

You could do the first one in each array like this
string $newStr = $selection[0] +"."+ $selCBAttr[0]

or loop through the objects and channels
string $newStr;
for($s in $selection)
for($a in $selCBAttr) {
$newStr = ($s + "." + $a);
print ($newStr + "\n");
}
}

David

DEVILSAN
11-06-2011, 11:42 AM
so now it got

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

string $selCBAttr[] = `selectedChannelBoxAttributes`;
string $newStr = "\"" + $selection[0] +"."+ $selCBAttr[0] + "\"";

setAttr -lock true $newStr ;

// Error: No object matches name: "pCube1.rz" //

even when pCube1 's RotateZ is selected for instance...

NaughtyNathan
11-06-2011, 02:46 PM
this is quite confusing if you don't fully appreciate the difference between variables and explicit strings, and how either is passed into functions.
you are creating a string variable that CONTAINS quotes (") and then passing it into the setAttr function, rather than using the quotes when denoting an explicit string.

If you want to pass strings as variables directly into functions do NOT add ". if you want to pass them in using eval or string catenation you DO add ".

// using a bare string variable:
string $string = $selection[0] + "." + $selCBAttr[0];
setAttr -lock true $string; // this works fine

// using a quoted string, must be eval-ed (directly or implicitely)
string $quotedString = "\"" + $selection[0] +"."+ $selCBAttr[0] + "\"";
eval ("setAttr -lock true " + $quotedString ); // this also works fine

// using NO variables at all (the preferred method)
setAttr -lock true ( $selection[0] + "." + $selCBAttr[0] ); // don't forget catenation braces
Hope that is some help.
:nathaN

DEVILSAN
11-06-2011, 04:19 PM
if i have multiple attributes selected I am trying to lock all of them one by one like this

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

string $selCBAttr[] = `selectedChannelBoxAttributes`;

for ($lstA in $selCBAttr)
{
print ($lstA + "\n");
int $i=0;

setAttr -lock true ( $selection[$i] + "." + $selCBAttr[$i] );
print ("\n " + $i + "\n") ;
$i++;
print ("\n " + $i + "\n") ;

}

i guess i need to understand for looo better, but even if i try to do it like this


for ($i = 0; $i++)

{

setAttr -lock true ( $selection[$i] + "." + $selCBAttr[$i] );

}



I get error though as fas i remember i can skip the middle option of the for loop...

WesHowe
11-06-2011, 06:48 PM
for ($i = 0; $i++)



for() requires three operands, as in:

for( $i=0; $i<size(myArray); ++$i)


<* Wes *>

procanic
11-07-2011, 09:54 AM
i have a shelfButton for channel control that i've been using for quite some time. the command for editing selected channels looks like this:

global proc setSelectedCBattributes(int $lock, int $key, int $vis)
{
channelBox -e -exe ("setAttr -lock " + $lock + " -keyable " + $key + " -channelBox " + $vis + " \"#P.#A\";") true mainChannelBox;
}
// e.g. to lock and make unkeyable but keep visible :
setSelectedCBattributes(1,0,1);


hope that's what you were looking for ...
cheers!:)
rob

PS:
you could also add RMB menus to the shelfButton for the different options (lock/unlock, keyable/unkeyable, etc.) ...

EDIT:
for details on channelBox command & explanation of -execute flag see:
http://download.autodesk.com/us/maya/2009help/Commands/channelBox.html

CGTalk Moderation
11-07-2011, 09:54 AM
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.