View Full Version : Locking Attributes with PopUpMenu
xcomb 08-02-2006, 04:11 PM Hi i am kinda confuse and i got somewhat working my script.
Here is the brief what i want to do, i have popup menu that has LockMe function calls
in LockMe() function i have this source
I get syntax error
global proc listConnection()
{
if (`window -exists connectionWindow`)
deleteUI connectionWindow;
//windowPref -r connectionWindow;
//windowPref -q -wh connectionWindow;
window -title "Connection Window" -wh 273 441 connectionWindow;
columnLayout -adj 1 connectionCol;
textScrollList -w 273 -h 400 -allowMultiSelection true connectionTSL;
popupMenu;
menuItem -label "Lock" -c "LockMe()" menuOne ;
menuItem -label "Unlock";
string $listAttributes[] = `textScrollList -q -si mainTSL`;
string $attrs[] = `listAttr -v -keyable $listAttributes[0]`;
int $listSize = size($attrs);
for($i = 0; $i < $listSize; $i++)
{
//print ($attrs[$i]);
textScrollList -e -a $attrs[$i] connectionTSL;
//int $lock = `getAttr -lock $listAttributes.translateX`;
}
showWindow connectionWindow;
}
global proc LockMe()
{
string $selected[] = `textScrollList -q -si mainTSL`;
string $list[] = `textScrollList -q -si connectionTSL`;
float $size = size($list);
for($i = 0; $i < $size; $i++)
{
//setAttr -lock false ($selected + ". $list");
setAttr -lock false ($selected+."+" $list);
}
}
As you can see i want to lock attributes of selected shapeNode and i've tryed couple ways i know, that didn't work for me, don't know what i do.
//setAttr -lock false ($selected + ". $list");
//setAttr -lock false ($selected+."+" $list);
Also this error
// Error: Illegal operation "+" on data of type string[]. //
Thanks in Advanced!
|
|
isoparmB
08-03-2006, 03:24 AM
You should use:
setAttr -lock false ($selected[0] + "." + $list[$i]);
for your script to cycle through all your attributes. When you try to add the elements of a string array, you have to indicate what element you want to use using the solid brackets.
xcomb
08-03-2006, 07:52 AM
I wonder did it work for you?
I've done the way you wrote, which makes perfect sence, that it should work, but i think i am too newbie to figure out on my own.
I get this new error :(
Wiered but i've checked them all, and they all show correct syntax
// Error: Invalid attribute name: pSphere1. //
isoparmB
08-03-2006, 08:38 AM
global proc listConnection()
{
if (`window -exists connectionWindow`)
deleteUI connectionWindow;
//windowPref -r connectionWindow;
//windowPref -q -wh connectionWindow;
window -title "Connection Window" -wh 273 441 connectionWindow;
columnLayout -adj 1 connectionCol;
textScrollList -w 273 -h 400 -allowMultiSelection false mainTSL;
textScrollList -w 273 -h 400 -allowMultiSelection true connectionTSL;
string $attrs[] = `ls -sl`;
textScrollList -e -a $attrs[0] mainTSL;
textScrollList -e -sii 1 mainTSL;
popupMenu;
menuItem -label "Lock" -c "LockMe()" menuOne ;
menuItem -label "Unlock" -c "UnlockMe()" menuTwo;
string $listAttributes[] = `textScrollList -q -si mainTSL`;
$attrs = `listAttr -v -keyable $listAttributes[0]`;
int $listSize = size($attrs);
for($i = 0; $i < $listSize; $i++)
{
//print ($attrs[$i]);
textScrollList -e -a $attrs[$i] connectionTSL;
//int $lock = `getAttr -lock $listAttributes.translateX`;
}
showWindow connectionWindow;
}
global proc LockMe()
{
string $selected[] = `textScrollList -q -si mainTSL`;
string $list[] = `textScrollList -q -si connectionTSL`;
float $size = size($list);
for($i = 0; $i < $size; $i++)
{
//setAttr -lock false ($selected + ". $list");
setAttr -lock true ($selected[0] + "." + $list[$i]);
}
}
global proc UnlockMe()
{
string $selected[] = `textScrollList -q -si mainTSL`;
string $list[] = `textScrollList -q -si connectionTSL`;
float $size = size($list);
for($i = 0; $i < $size; $i++)
{
//setAttr -lock false ($selected + ". $list");
setAttr -lock false ($selected[0] + "." + $list[$i]);
}
}
There were a number of things I noticed. Your initial global proc did not contain the text scrol list command for the mainTSL (unless you had this in a separate code you did not post). And the script was dependent on the mainTSL having an item already in it for the script to function, so I had to make it input the first object I had selected using the ls -sl command. Also, your lock command is wrong, the arguement for the lock flag should be true for it to lock. I also added in an unlock proc. It works fine on my side now.
xcomb
08-03-2006, 09:41 AM
WOW thanks it worked!!!
I just had to copy this to make it to work, which doesn't make sence why in the first place it didn't work :)
That's all i've changed in my script and boom works.
Strange i had it written in first place when you corrected me.
global proc LockMe()
{
string $selected[] = `textScrollList -q -si mainTSL`;
string $list[] = `textScrollList -q -si connectionTSL`;
float $size = size($list);
for($i = 0; $i < $size; $i++)
{
//setAttr -lock false ($selected + ". $list");
setAttr -lock true ($selected[0] + "." + $list[$i]);
}
}
global proc UnlockMe()
{
string $selected[] = `textScrollList -q -si mainTSL`;
string $list[] = `textScrollList -q -si connectionTSL`;
float $size = size($list);
for($i = 0; $i < $size; $i++)
{
//setAttr -lock false ($selected + ". $list");
setAttr -lock false ($selected[0] + "." + $list[$i]);
}
}
xcomb
08-03-2006, 03:23 PM
Well everything is fine, except that i got struck with second issue :)
I have two transform nodes selected that have attributes, i want to see and lock them or unlock both at the same time, not one by one.
So the thing is, i got working only one object, which shows it's attributes and locks them.
Here is the script that i am trying to get it fixed.
global proc listConnection()
{
if (`window -exists connectionWindow`)
deleteUI connectionWindow;
//windowPref -r connectionWindow;
//windowPref -q -wh connectionWindow;
window -title "Connection Window" -wh 273 441 connectionWindow;
columnLayout -adj 1 connectionCol;
textScrollList -w 273 -h 400 -allowMultiSelection true connectionTSL;
popupMenu;
menuItem -label "Lock" -c "LockMe()" menuOne ;
menuItem -label "Unlock" -c "UnlockMe()" menuTwo;
// That's where i get that problem is i have both selected but only one display it's attribute
string $listAttributes[] = `textScrollList -q -si mainTSL`;
int $listSize = size($listAttributes);
for($j = 0; $j < $listSize; $j++){
string $listAttr[] = `listAttr -v -keyable $listAttributes[$j]`;
int $stuff = size($listAttr);
for($i = 0; $i < $stuff; $i++){
string $new = `textScrollList -e -a $listAttr[$i] connectionTSL`;
}
}
showWindow connectionWindow;
}
CGTalk Moderation
08-03-2006, 03:23 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.
vBulletin v3.0.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.