View Full Version : using string or array to setAttr


indestructibleman
04 April 2005, 01:06 AM
i'm writing a rig in script form and i want to make translate, scale and visibility attributes non-keyable on all my bones.

i've tried using a string list like;
string $ls[] = {
"cl_spineaJNT",
"cl_spinebJNT",
"cl_spinecJNT",

};
string $n;
for ($n in $ls)
{
setAttr -k off $n.translateX;
setAttr -k off $n.translateY;
setAttr -k off $n.translateZ;

setAttr -k off $n.scaleX;
setAttr -k off $n.scaleY;
setAttr -k off $n.scaleZ;

setAttr -k off $n.visibility;
};


i've also tried
string $bone[];
$bone[0] = "cl_spineaJNT";
$bone[0] = "cl_spinebJNT";
$bone[0] = "cl_spinecJNT";

setAttr -k off $bone.translateX;
setAttr -k off $bone.translateY;
setAttr -k off $bone.translateZ;

setAttr -k off $bone.scaleX;
setAttr -k off $bone.scaleY;
setAttr -k off $bone.scaleZ;

setAttr -k off $bone.visibility;


i actually have many more joints to list, but i'm testing this using just three. unfortunately, i keep getting an error saying Invalid use of Maya object for each of the joints named.

any suggestions?

cheers,
will

Iconoklast
04 April 2005, 11:38 AM
try this:

setAttr -k off ($bone[0] + ".visibility");

indestructibleman
04 April 2005, 09:28 PM
ok. that's better.
but now i can only do one element at a time, which in this case doesn't really help.

i eventually came up with this, which is really nice (i think).

select cl_spineaJNT;
select -hi;
string $bones[] = `ls -sl`;
string $attrs[]={"tx","ty","tz","sx","sy","sz","v"};

for ($attr in $attrs)

for ($b in $bones)
{
setAttr -l on ($b + "." + $attr);
setAttr -k off ($b + "." + $attr);
};


thanks,
will

Iconoklast
04 April 2005, 12:07 AM
string $bone[];
$bone[0] = "cl_spineaJNT";
$bone[1] = "cl_spinebJNT";
$bone[2] = "cl_spinecJNT";

for ($i = 0; $i < size($bone); $i++)
{
setAttr -k off ($bone[$i] + ".translateX");
setAttr -k off ($bone[$i] + ".translateY");
setAttr -k off ($bone[$i] + ".translateZ");

setAttr -k off ($bone[$i] + ".scaleX");
setAttr -k off ($bone[$i] + ".scaleY");
setAttr -k off ($bone[$i] + ".scaleZ");
setAttr -k off ($bone[$i] + ".visibility");
}

is a bit cleaner. It will loop through everything in $bone. And perform the setAttr on each bone.

CGTalk Moderation
04 April 2005, 12:07 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.


1