Adding attributes

I'm trying to add custom attributes to an object that I'm creating with a loop, but it keeps stopping after the 2nd cube is created.

What am I doing wrong?

1
2
3
4
5
6
7
8

for ($i=1 ; $i<=$objectCount ; $i++) // we use a loop to CONSTRUCT the expression string
{
polyCube -n $name;
move -r $i 0 0;
addAttr -ln "column_delay" -at double -min 0 -max 100 $name;

$expr += ("master"+$i+".ry = `getAttr -t (frame-("+$frame\_delay+"*"+$i+")) master.ry`;\n");

};

problem is here:

polyCube -n $name;

Well maya doesn't actually work that way, see maya at its own discretion WILL RENAME YOUR cube since there can not ever be a naming clash. So what you have to do is actually catch what maya named the cube and act on that. 

However your code is a bit inefficient there's actually a easier way to accomplish the same thing. And that to just create one object and duplicate input network 100 times.

About your expression:

you should avoid using mel inside expressions, its going to get you into BIG PROBLEMS in the long run. Its inefficient and subverts how the dag is supposed to work. The time you save now is insignificant to the time you loose when you hit the wall with this method and cant hack it what the showe comes to push because you TOUGHT you had things solved. So no getAttr except under very controlled environments. Here you dont need it for anything.

so what should I be doing instead?

you should use ($name + $i) in stread of $name

Well Duvekots answer does work superficially but you should ALWAYS catch the name off whatever you do explicitly in case maya decides to rename you.

$realName=polyCube -n ($name+$i);

and then use $realName[0] in subsequent calls to name.

Applies to ALL mel programming, always catch the name (prefeerably the long name) just in case maya decided to override you,

so what should I be doing instead?

use a frame cache node