Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Scripting – convert expression to keyframes

  • Scripting – convert expression to keyframes

    Posted by Kevin Snyder on October 25, 2022 at 7:29 pm

    I have a script to turn on a specific expression and convert the expression to keyframes. It works, however, if there are other properties with expressions selected when it’s run, all the selected properties with expressions get converted to keyframes. Is there a way to ensure that only myProp gets converted to keyframes?

    function addKeys(){

    var myComp = app.project.activeItem;

    var myLayers = myComp.selectedLayers;

    if (myLayers.length > 0){

    var myLayer = myLayers[0];

    for (var i = 0; i < myLayers.length; i++){

    try{

    var myProp = myLayers[i].effect("Opacity Controller")("Opacity Offset");

    myProp.expressionEnabled = true;

    myProp.selected = true;

    app.executeCommand(app.findMenuCommandId("Convert Expression to Keyframes"));

    }catch(err){}

    }

    }

    }

    Kevin Snyder replied 1 year, 9 months ago 2 Members · 2 Replies
  • 2 Replies
  • Dan Ebberts

    October 25, 2022 at 7:56 pm

    Once you’ve capture the selected layers into myLayers, I think you need to deselect them all, so that only one property at a time is selected:

    function addKeys(){
    var myComp = app.project.activeItem;
    var myLayers = myComp.selectedLayers;
    if (myLayers.length > 0){
    var myLayer = myLayers[0];
    for (var i = 0; i < myLayers.length; i++){
    myLayers[i].selected = false;
    }
    for (var i = 0; i < myLayers.length; i++){
    try{
    var myProp = myLayers[i].effect("Opacity Controller")("Opacity Offset");
    myProp.expressionEnabled = true;
    myProp.selected = true;
    app.executeCommand(app.findMenuCommandId("Convert Expression to Keyframes"));
    }catch(err){ }
    myLayers[i].selected = false;
    }
    }
    }
  • Kevin Snyder

    October 26, 2022 at 4:26 pm

    That did the trick! Thank you.

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy