First, please note the difference between:
expressions - pieces of mel code attached to objects, driving atrributes and executed as animation plays ( every frame )
and
scripts - pieces of mel code executed by user. Commonly used to automate things you do thru ui; object creation and editing, animating, etc.
By looking at your posts I kinda got the feeling that you don't see a difference between two. Maybe I'm wrong.
So, what you posted above is exspression - the thing that drives the animation. What I posted before you is script - the thing you'll use to automate creation of 500 objects.
To see how scripts work try this: Open the script editor ( not expression editor ) and in the bottom field type:
global proc myCommand( int $n ){
int $i;
for( $i = 1; $i <= $n; ++$i ){
print $i;
print " ";
}
}
Now select all you typed and press ctrl+enter. This will execute the script. Since this script is definition of custom procedure you won't see any output. Now in the command line type:
myCommand( 10 );
and check out the output in the script editor upper window. Your custom procedure gets called just like any other mel command ( of course it does not do anything useful, just prints out some numbers )
Now paste following into script editor:
global proc duplicateMyStuff( int $numCopies, string $loc1Name, string $loc2Name, string $polyName ){
float $copyOffset = 2;
// unparent
eval( "parent -w " + $loc1Name + "|" +$loc2Name + "|" +$polyName );
eval( "parent -w " + $loc1Name + "|" +$loc2Name );
// loop
int $n;
for( $n = 1; $n<= $numCopies; ++$n ){
string $loc1NewName = "loc1_copy" + $n;
string $loc2NewName = "loc2_copy" + $n;
string $polyNewName = "poly_instance" + $n;
duplicate -n $loc1NewName $loc1Name;
duplicate -n $loc2NewName $loc2Name;
instance -n $polyNewName $polyName;
parent $polyNewName $loc2NewName;
parent $loc2NewName $loc1NewName;
// move result a bit
move -r ( $n * $copyOffset ) 0 0 $loc1NewName;
}
// end of loop
// reparent
parent $polyName $loc2Name;
parent $loc2Name $loc1Name;
}
// end of script
select it and press ctrl+enter.
Make sure that you have loc1->loc2->poly hiearachy in your scene and in command line type: duplicateMyStuff( 500, "loc1", "loc2", "poly" )
Tweak a script to suit your specific needs.
Regarding seed:
All random number generators are in fact pseudo-random. They start from some number called seed and generate random looking sequence. Same seed - same sequence.
By setting seed before calling each random you are acctually forcing it to generate exactly the same number over and over. Just delete the seed line and it should be ok.
If you want "same randomness" each time animation plays just create new locator or some other dummy object and attach expression:
if( frame == 1 ){
seed( 1 )
}
Now seed() gets executed only once for the whole scene at the start of animation