Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Button that inputs expression from UI Panel

  • Button that inputs expression from UI Panel

    Posted by Scott Mcgee on March 15, 2017 at 9:59 pm

    I can’t think of any other way to word the subject.

    I have scoured everywhere and cannot find what I am looking for as bizarre as it sounds. I have found threads where people want to create a script to add an expression, some who want an expression to add to multiple layers at once.

    I have created a UI Panel with a button (Well a few buttons and dropdownlists), when I select my layer and click the button it will place the expression onto that property.

    So for example.

    myBtn: Panel{text:’Station Selector’, orientation:’row’, alignChildren:[‘left’, ‘fill’],\
    Wiggle: Button{text:’Wiggle’},\

    I have my button, if I assign it to change text etc

    myPanel.grp.myBtn.Wiggle.onClick = function(){
    var myComp = app.project.activeItem;
    myComp.layer(“[Station]”).property(“ADBE Text Properties”).property(“ADBE Text Document”).setValue(“Wiggle”);

    This works fine.

    What I would like it to do is something on the lines of based off what I’ve seen and guessing at.

    myPanel.grp.myBtn.Wiggle.onClick = function(){
    var myComp = app.project.activeItem;
    myComp.selectedLayers.property.expression = ‘[wiggle (2,10)]’;

    I’m using wiggle as a simpler expression, as I want to use more beefy expression, but essentially I want the button to add the expression to property I’ve selected. I want to set up something where I don’t have to keep copying and pasting the expression. So I want a button that will just put it in.

    Any help would be greatly appreciated

    Scott Mcgee replied 9 years, 5 months ago 2 Members · 2 Replies
  • 2 Replies
  • Dan Ebberts

    March 16, 2017 at 12:49 am

    Your function might look like this:


    var myComp = app.project.activeItem;
    var myExpression = 'wiggle (2,10)';
    var myProps = myComp.selectedProperties;
    for (var i = 0; i < myProps.length; i++){
    if (myProps[i].canSetExpression){
    myProps[i].expression = myExpression;
    }
    }

    Dan

  • Scott Mcgee

    March 16, 2017 at 9:03 am

    Thank you very much Dan.

    hahaha, I didn’t see this and literally found something similar you wrote for someone else

    var myEffect = myLayer.Effect.addProperty(“ADBE Slider Control”);
    var myExpr = “amp = effect(1)(“Slider”);” + “r” +
    “freq = effect(2)(“Slider”);” + “r” +
    “x = … etc. ;”;

    myLayer.property(“position”).expression = myExpr;

    So I reworked it to reflect what you’ve put


    applyButton.onClick = function(){
    props = app.project.activeItem.selectedProperties;
    for (var i = 0; i < props.length; i++){
    if (props[i].canSetExpression){
    props[i].expression = “input = thisComp.layer(\”[Colour]\”).text.sourceText; if( (input == \”red\”) == 1) value else 0;”;
    }
    }

    I was going to ask if there was a way to create a textStr in the expression, so you can put your own variable to your layers and click the button and it will add it to all those layers. Found another one of your wonderful threads and came up with this

    applyButton.onClick = function(){
    props = app.project.activeItem.selectedProperties;
    textStr = addScript.text;
    for (var i = 0; i < props.length; i++){ if (props[i].canSetExpression){ props[i].expression = "input = thisComp.layer(\"[Station]\").text.sourceText; if((input == \"" +textStr+ "\") == 1) value else 0;"; } } }

    I’m starting to enjoy this script building malarky.

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