Maya MEL variable time range for bakeSimulation-Command


#1

Hi Folks,

first of all, I am an animator and not well learned scriptor by now. But I tried to build a basic script, that creates a simple random camera-shake in MEL. What I’ve got so far is, create a Shake-Group with a Locator, bake tx & ty anim of Locator on a new animLayer by 1 frames, randomize the keys, integrate it to cam-hierachy and parent the cam.
But I ran into the problem, that I have to set start and end of the timeline for the bakeSimulation-Command manually. I tried by query min maxTime via int and string-variables, but it does not work. Is there any way to do that better?
Here is the script:

// Generic Camera Shake
// select the cam to shake it!

string $selectCam[] = ls -sl;
print $selectCam;
select -cl;

doGroup 0 1 1;
rename “cameraShake_GRP”;
select -cl;

spaceLocator -n “cameraShake_LOC”;
parent cameraShake_LOC cameraShake_GRP;

select $selectCam;
select -add cameraShake_GRP;

string $selection[] = ls -sl;
string $snapCon1[] = parentConstraint $selection[0] $selection[1];
delete $snapCon1;

// set timerange (start:end)!

select “cameraShake_LOC”;
bakeSimulation -t “1001:1101” -bol true -sb 1 -at tx -at ty;
rename BakeResults cameraShake_Layer;

// random keys from -2 - 2

float $random;
int $n=keyframe -q -kc cameraShake_LOC.tx;

for($i=0;$i<$n;$i++) {
$random=rand -2 2;
keyframe -e -at tx -in $i -vc $random cameraShake_LOC;
}

float $random;
int $n=keyframe -q -kc cameraShake_LOC.ty;

for($i=0;$i<$n;$i++) {
$random=rand -2 2;
keyframe -e -at ty -in $i -vc $random cameraShake_LOC;
}

select $selectCam;

pickWalk -d up;
string $camFather[] = ls -sl;
print $camFather;
select -cl;

parent cameraShake_GRP $camFather;
parent $selectCam cameraShake_LOC;

print “The cam is shaking now! Have fun.”;