|
So I wrote a simple script to rotate a bunch of objects at random angles. For reference here it is:
// Script for setting the rotation of a group of objects at random angles.
// Author(s): Dorian Patterson
// License: Public Domain, or least restrictive open source license available.
// Short explanation: This script requires that all the object be labelled in post numerical order. i.e. pCube1, pCube2, pCube3, ..., pCube#, where # is the nth version of the object.
// $max = Maximum number of items to rotate. Substitute with appropriate value.
int $max = 10; for(int $i = 1; $i <= $max; $i++)
{
// $prefix = the prefix for the object to rotate. In this example for a default polygon cube, it's pCube.
$prefix = "pSphere";
// $name = name of the current object to rotate. It will be appended by the current count number $i.
$name = $prefix + $i;
// Selects the object.
select $name;
// Starts a new seed with the current count value.
// Generates random values between 0 and 360. These are floating point numbers.
$rotX = rand(360)
$rotY = rand(360)
$rotZ = rand(360)
// Finally the most important function, rotates the object with the set values.
rotate $rotX $rotY $rotZ; };
When I first use it in a scene, it works fine. I can reuse it multiple times over and over. Everything is hunky-dory.
The problem comes after reloading the scene. The first time this happened, I got errors about using an incompatible operator on a string. For some reason $max was being interpreted as a string. I tried renaming the variable, implicitly declaring its type as int, but none of that worked. Restarting Maya did.
Now, it complains about a syntax error. Again, restarting Maya solves the problem, but that is a stupid workaround. Am I missing a simple fix, or is Maya just a pain in the -insert body part here-?
Thanks for any help!
|