View Full Version : collision layer script not working. Please help.
lacluna 12-06-2011, 05:58 PM Hello every body. I created this script:
string $rb[] = `ls -type rigidBody`;
int $y = 1;
for ($x in $rb)
{
setAttr ($z+ ".collisionLayer"+" "+$y);
int $y = $y+1;
}
I get the following error:
Error: setAttr: No object matches name: "pirateDebris1.collisionLayer" 1
If I set it manually it works:
setAttr pirateDebris1.collisionLayer 1
Any suggestions?? Thank you
|
|
NaughtyNathan
12-06-2011, 07:42 PM
you don't init a $z variable in this example, and you don't reference $x in the loop, but I'm assuming this is either a typo or due to this being a code snippet.
you are telling the setAttr command to set the name: "pirateDebris1.collisionLayer" 1
notice how the space and the 1 is included in the string, so that whole string is being passed to the setAttr command as a single input, hence the error:
// no object matches name "pirateDebris1.collisionLayer" 1
you need to do this:
setAttr ($z+ ".collisionLayer") $y;
so you are only passing the object.attr name as a string and the 1 ($y) as a second parameter.
also, you are redefining $y as an int inside the loop, so Maya will think you are trying to create a NEW variable called $y just inside the for..loop. Don't put the variable type when you simply want to refer to an existing variable, otherwise you'll be recreating a new variable.
string $rb[] = `ls -type rigidBody`;
int $y = 1;
for ($x in $rb)
{
setAttr ($z+ ".collisionLayer") $y;
$y++; // a short-hand way of incrementing a var by 1
}
:nathaN
CGTalk Moderation
12-06-2011, 07:42 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-2013, Jelsoft Enterprises Ltd.