jHromika
06-05-2004, 03:55 AM
Sounds like a simple enough request. :)
Basically, we'll be using two main commands here, listAttr and setAttr .
As an example, create a nurbs sphere. We'll use listAttr here to find out which attributes we'll be zeroing out.
In the script editor enter:
listAttr -keyable nurbsSphere1;
You should get something like this...
// Result: visibility translateX translateY translateZ rotateX rotateY rotateZ scaleX scaleY scaleZ //
The keyable flag is used because it will return everything that appears in the channel box. This way, any extra attributes are picked up, while hidden ones will be ignored.
We're going to want this to be stored in a variable for further use though. So we'll define a string array...
string $attr[];
And then use backticks to get listAttr to evaluate and fill up the array.
$attr = `listAttr -keyable nurbsSphere1`;
So now we have an array containing each attribute from the channel box. Here is where setAttr comes into play. We can use this line...
setAttr ("nurbsSphere1." + $obj) 0;
...within a for loop to take each one of those attributes and set it to 0. The problem there, is that I'm assuming you don't want scale or visibility to become 0 also.
One way to do this, would be to use stringArrayRemove
So we'll define another string array with scale and visibility. Then, if those attributes turn up in our $attr array, they will be removed and their original values retained.
At this point, the script looks like this...
string $attr[];
string $badAttr[] = {"scaleX", "scaleY", "scaleZ", "visibility"};
$attr = `listAttr -keyable nurbsSphere1`;
string $newAttr[] = stringArrayRemove($badAttr, $attr);
for ($a in $newAttr)
setAttr ("nurbsSphere1." + $a) 0;
...which looks great if the only object you want this to work on is nurbsSphere1 :rolleyes:
So, just like we stored the attributes into an array, we'll do the same for selected objects.
First define the string array...
string $objects[];
Then, use ls along with the backticks to fill the array.
$objects = `ls -selection`;
We'll set up another loop since we potentially have multiple selections now.
for ($obj in $objects)
{
...
}
and replace all instances of nurbsSphere1 with $obj.
The code now stands to look like this...
string $objects[];
string $attr[];
string $badAttr[] = {"scaleX", "scaleY", "scaleZ", "visibility"};
$objects = `ls -selection`;
for ($obj in $objects)
{
$attr = `listAttr -keyable $obj`;
string $newAttr[] = stringArrayRemove($badAttr, $attr);
for ($a in $newAttr)
setAttr ($obj + "." + $a) 0;
}
Then if you want, this could be taken one step further and placed into a UI. I'll save the UI details though, and just post a final script :)
global proc jhZeroOut ()
{
$win = "jhZeroOutWIN";
if (`window -exists $win`)
deleteUI $win;
jhZeroOutWin $win;
showWindow $win;
}
global proc jhZeroOutWin (string $win)
{
window -t "jhZeroOut" -rtf true $win;
columnLayout -cat both 5 -adj true;
separator -height 5 -style "none";
button -l "Zero Out Attributes" -c jhZeroOutRun;
}
global proc jhZeroOutRun ()
{
string $objects[];
string $attr[];
string $badAttr[] = {"scaleX", "scaleY", "scaleZ", "visibility"};
$objects = `ls -selection`;
for ($obj in $objects)
{
$attr = `listAttr -keyable $obj`;
string $newAttr[] = stringArrayRemove($badAttr, $attr);
for ($a in $newAttr)
setAttr ($obj + "." + $a) 0;
}
}
Just copy and paste that into the script editor and execute it. Then enter jhZeroOut to open the window. Any objects you have selected when you click the button will have all keyable attributes changed to 0 (excluding scale and visibility).
If you have any questions on anything I didn't explain well enough, feel free to ask :)
stickyblue
06-10-2004, 11:30 PM
hey thanks a bunch !!! that just tought me muuch more than I was expecting !
CGTalk Moderation
01-18-2006, 08:00 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.
vBulletin v3.0.5, Copyright ©2000-2013, Jelsoft Enterprises Ltd.