Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Scripting a slider for color control between multiple layers

  • Scripting a slider for color control between multiple layers

    Posted by Lee Pines on October 10, 2020 at 1:23 pm

    Hello!

    I’m trying to script an common after effects project to be reused for several productions that has multiple elements who’s background changes color depending on the production.

    I want to make a slider that anyone can just slide to change the color of all elements easily when the project file is reused.

    I have a null layer (named “Color”) with a slider and 13 different color control effects. I’m pulling all this into essential graphics.

    Then I add an expression to each fill of each element. However, I’m getting a syntax error in my expression. Can you help me figure out what’s wrong with my expression?

    Here’s the fill expression:

    slider = Math.floor(thisComp.layer(“<wbr>Color”).effect(“Slider Control”)(“Slider”).value);
    if (slider == 1)
    effect(“Color Control”)(“Color”)
    else if (slider == 2)
    effect(“Color Control 2”)(“Color”)
    else if (slider == 3)
    effect(“Color Control 3”)(“Color”)
    else if (slider == 4)
    effect(“Color Control 4”)(“Color”)
    else if (slider == 5)
    effect(“Color Control 5”)(“Color”)
    else if (slider == 6)
    effect(“Color Control 6”)(“Color”)
    else if (slider == 7)
    effect(“Color Control 7”)(“Color”)
    else if (slider == 8)
    effect(“Color Control 8”)(“Color”)
    else if (slider == 9)
    effect(“Color Control 9”)(“Color”)
    else if (slider == 10)
    effect(“Color Control 10”)(“Color”)
    else if (slider == 11)
    effect(“Color Control 11”)(“Color”)
    else if (slider == 12)
    effect(“Color Control 12”)(“Color”)
    else if (slider == 13)
    effect(“Color Control 13”)(“Color”)

    Michael Szalapski replied 5 years, 7 months ago 7 Members · 9 Replies
  • 9 Replies
  • Brendon Murphy

    October 10, 2020 at 3:54 pm

    If you’re wanting each color control to change based on the slider, the expression on each color control should be like this:

    slider = Math.round(effect(“Slider Control”)(“Slider”));

    colorValue1 = [1,1,0,1];//put your desired color values here

    colorValue2 = [1,0,0,1];//put your desired color values here

    if(slider==1){colorValue1};

    if(slider==2){colorValue2};

    And so on. I’d also put stipulations for if the slider is less than 1 or greater than your highest assigned value so there are no errors.

  • Michael Szalapski

    October 10, 2020 at 6:19 pm

    Although, if you’re using the current versions, you might be better-suited using a drop-down menu instead of a slider like this.

  • Daniel Gillies

    October 10, 2020 at 6:55 pm

    Not sure if this is especially helpful, but Ray Dynamic Color is an elegant solution for these types of problems.

  • Walter Soyka

    October 10, 2020 at 7:44 pm

    I strongly agree with the suggestion to use a dropdown — they’re much easier for your template’s users to understand and use.

    Here’s some documentation on how to set them up:

    https://helpx.adobe.com/after-effects/using/create_dropdowns_using_expressions.html

  • Dan Ebberts

    October 10, 2020 at 9:09 pm

    I think you just need to a default case so the expression has something to do if the slider goes outside the 1-13 range. So you could just add this to the end of your expression so the color goes to black if the slider goes out of range:

    else

    [0,0,0,1]

  • Roland R. kahlenberg

    October 11, 2020 at 12:23 am

    You should use curly brackets to encapsulate your “if … else” conditionals.
    Something like the following –

    slider = Math.floor(thisComp.layer(“<wbr>Color”).effect(“Slider Control”)(“Slider”).value);
    if (slider == 1) {
    effect(“Color Control”)(“Color”)
    } else if (slider == 2) {
    effect(“Color Control 2”)(“Color”)
    } else if (slider == 3) {

    }

    And as others have suggested, a Dropdown Menu is preferred for a more elegant UI/UX. You’ll want to be use descriptive a name for each Color Theme/Selection to make it onto the “This Week’s Awesome Dropdown Menu List”. 🙂

    And for completeness, if you ever need to use a Slider Control for discreet selection/action, you’ll want to apply the Math.floor Expression directly onto the Slider Control instead of applying it onto the effect being controlled by the Slider Control.

  • Lee Pines

    October 11, 2020 at 11:38 am

    Thanks for the response. The problem isn’t the slider, it’s connecting it to another layer. BUT, how would you make the dropdown?

  • Lee Pines

    October 11, 2020 at 11:41 am

    Thanks! The problem isn’t with this part of the code, it’s with the first line. I can’t seem to make it connect to another layer properly. The code works fine without thisComp.layer(“Color”) so I’m wondering what’s wrong with this part of the code

  • Michael Szalapski

    October 12, 2020 at 3:38 am

    Walter’s reply should cover you on how to make the dropdown with this link.

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