Forums › Adobe After Effects Expressions › [HELP] Script to convert all expressions into keyframes
-
[HELP] Script to convert all expressions into keyframes
-
Vincenzo Imbimbo
March 28, 2022 at 4:01 pmHi! I’m trying to create a script that converts all the expressions to keyframes, i have a bunch of layers with expressions in the “Position” property, and i need to convert it to keyframes.
I found this post: https://creativecow.net/forums/thread/bulk-convert-expressions-into-keyframes/ where Dan wrote a code but i’m trying to run it and i get this error:
Syntax error in line:
app.executeCommand(app.findMenuCommandId(“Convert Expression to Keyframes”));
This is the code by Dan:
(Dan if you are reading this pls help me!)
{
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(); } } -
Dan Ebberts
March 28, 2022 at 4:32 pmUnfortunately, a lot of the code posted before this site did its most recent upgrade got mangled in the upgrade process. It’s usually where straight quotes get replaced with smart quotes and hyphens get replace with em (or en ?) dashes. In any case, try this cleaned up version:
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();
}
-
Vincenzo Imbimbo
March 28, 2022 at 4:43 pmThank you so much Dan! This is exactly what i needed, you are such a pro!
Log in to reply.