Animation bake in MEL to a specific animation layer

coding
maya

#1

Hello,
I’m trying to bake an animation to a specific animation layer but I’m running into issues. If I specify a target I get a different result than if I don’t specify a target layer to bake to. Like this:

float $minTime = `playbackOptions -q -minTime` ;
if ( `animLayer -q -exists OverlapAnimation` == 0 )
    {
        animLayer OverlapAnimation ;
    }
$selected = `ls -selection` ;
currentTime $minTime ;
float $worldPos[] = `xform -q -ws -t $selected[0]` ;
bakeResults -simulation true -at "tx" -at "ty" -at "tz" -time ($minTime + ":" + $maxTime) -sampleBy 1 -oversamplingRate 1 -dic true -pok true -sac true -rba false -ral false -bol true -destinationLayer OverlapAnimation {( $selected[0])} ;

Try that bit of code on a clean scene with a single object selected, the object needs to be moved a bit so you can see the effect. When I run that code my object is moved twice the distance it had originally.

If that code is run without the -destinationLayer OverlapAnimation you will get a different result.

I was wondering if anyone of you had run into this and how you solved it.

Thanks for the help!


#2

Apparently there were some things that stuck in the background yesterday. The code should look like this:

float $minTime = `playbackOptions -q -minTime` ;
float $maxTime = `playbackOptions -q -maxTime` ;
if ( `animLayer -q -exists OverlapAnimation` == 0 )
    {
        animLayer OverlapAnimation ;
    }
$selected = `ls -selection` ;
currentTime $minTime ;
float $worldPos[] = `xform -q -ws -t $selected[0]` ;
bakeResults -simulation true -at "tx" -at "ty" -at "tz" -time ($minTime + ":" + $maxTime) -sampleBy 1 -oversamplingRate 1 -dic true -pok true -sac true -rba false -ral false -bol true -destinationLayer OverlapAnimation ($selected[0]) ;