-
Quick and Dirty Expression Baker
I’m struggling with expression baking. Its very stupid and incredibly time consuming. For my needs, I don’t need all the extra things the default baking does, and smartbaker from AE scripts doesn’t fix the issue either.
I have a script that aligns/scales logos together, and another that dynamically adds text to a text layer. These things are static, no motion or anything like that. But the comps need to be long, like 10seconds long. Obviously baking these layers is a very long, time consuming process when really all I need is to bake the first frame, and then delete the keyframes generated. Typically, I’ve had to trim all my layers to 1 frame, highlight all the expressions of each layer, run the bake command, then delete the keyframes generated, and then re-extend all the layers back to what they were originally. It takes forever. And I want to see if I can find a better way to go about this.
Ideally, I need to figure out a way to just give a general command that says “If there is an expression applied to this selected layer, bake it”, but I don’t know what the correct code would be for that (its really difficult to find the things I need from the CS6 scripting guide).
So the process would be: 1. All layers selected, trim to 1 frame. 2. Identify expressions of each layer, and run AE’s bake command. 3. Delete created keyframes. 4. re-extend layers to the duration of the current comp.Below is a script Dan came up with a while back that does part of what I’m looking for, but I have to code for every possible expression in AE. For example, I would need to put in code to check for expression on source text. But I also don’t know how to trim a layer to 1 frame, then extend it back to the comp duration.
{function convertToKeyframes(theProperty){
if (theProperty.canSetExpression && theProperty.expressionEnabled){
theProperty.selected = true;
app.executeCommand(app.findMenuCommandId("Convert Expression to Keyframes"));
theProperty.selected = false;
}
}var myComp = app.project.activeItem;
if (myComp && myComp instanceof CompItem){
var myLayer;
var myProperty;
app.beginUndoGroup("convert expressions");
for (var i = 1; i <= myComp.numLayers; i++){
myLayer = myComp.layer(i);
try{
myProperty = myLayer.property("position");
convertToKeyframes(myProperty);
}catch(err){
}
try{
myProperty = myLayer.property("anchorPoint");
convertToKeyframes(myProperty);
}catch(err){
}
try{
myProperty = myLayer.property("rotation");
convertToKeyframes(myProperty);
}catch(err){
}
try{
myProperty = myLayer.property("scale");
convertToKeyframes(myProperty);
}catch(err){
}
try{
myProperty = myLayer.property("opacity");
convertToKeyframes(myProperty);
}catch(err){
}
}
app.endUndoGroup();
}}
Really, I’m practically there with Dan’s code. I’m just not sure about layer trimming, or deleting keyframes. But I understand whats going on here, I just don’t have the vocabulary to express it!