Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Use a script to apply an expression to a selected property

  • Use a script to apply an expression to a selected property

    Posted by Kevin Snyder on October 3, 2021 at 8:22 pm

    How do you write a script to apply an expression to a selected property? I’ve looked around old post, but many of them are older and no longer work. I’ve tried modifying them without any luck. Thanks.

    Kevin Snyder replied 4 years, 7 months ago 2 Members · 4 Replies
  • 4 Replies
  • Dan Ebberts

    October 3, 2021 at 8:28 pm

    This would be the basics:

    var myComp = app.project.activeItem;

    var myProps = myComp.selectedProperties;

    var myExpr = "value";

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

    if (myProps[i].canSetExpression) myProps[i].expression = myExpr;

    }

  • Kevin Snyder

    October 3, 2021 at 11:08 pm

    Thanks, Dan. I appreciate it. For some reason, it’s still throwing an error.

    When I use the script below I get a message stating “Unable to execute script at line 5. Expected: ;”

    var myComp = app.project.activeItem;

    var myProps = myComp.selectedProperties;

    var myExpr = "thisComp.layer("Master Null").effect("Drive")("Output 01")";

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

    if (myProps[i].canSetExpression) myProps[i].expression = myExpr;

    }

  • Dan Ebberts

    October 4, 2021 at 12:07 am

    In line 3, you’ve got conflicting quotes. Try it this way:

    var myExpr = 'thisComp.layer("Master Null").effect("Drive")("Output 01")';
  • Kevin Snyder

    October 4, 2021 at 4:21 am

    Great! Thank you.

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