Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Forums Adobe After Effects Expressions Change layer visibility via Essential Graphics

  • Change layer visibility via Essential Graphics

  • Matthias Schwarz

    November 6, 2017 at 1:35 pm


    this is my first post here so be kind if I do a mistake. I´m planning to dive deeper into expression controlled Essential
    Graphics-Template for Premiere CC. Recently I found a very interesting tutoria with a cool feature: choose a graphic by changing a slider value in the essential graphics panel.
    you can see it at minute 6:02, here is the link:

    Can anyone explain how this works? I mean, I understand how the slider-expression itself works. But I don´t understand what changes the graphic layers “behind the scenes.” I read a post where Dan Ebbert said you can´t control a layers visibility via expressions. What did this guy exactly?

    Yours, Matthias

    Some contents or functionalities here are not available due to your cookie preferences!

    This happens because the functionality/content marked as “Google Youtube” uses cookies that you choosed to keep disabled. In order to view this content or use this functionality, please enable cookies: click here to open your cookie preferences.

  • Kevin Camp

    November 6, 2017 at 8:08 pm

    you can’t use an expression to control whether a layer is active or not (by clicking the eyeball icon for a layer to show/hide it), but you can control visibility via the opacity property.

    so you can link a layer’s opacity to a slider, then set the opacity to 100 if the corresponding number is set by the slider or 0 if it is not. Something like this:
    ctrl = thisComp.layer("control").effect("Slider Control")("Slider");
    if ( Math.floor( ctrl ) == 1 ) 100 else 0;

    Kevin Camp
    Art Director

  • Matthias Schwarz

    November 6, 2017 at 10:11 pm


    thanks for the idea. I tried to control a couple of layers and it worked! Fine!

    I made a null object and put this expression into a slider control:


    An on every layer which is controlled by the slider I put this expression to the opacity:

    if (thisComp.layer(“Controller”).effect(“Slider”)(“Schieberegler”) == thisLayer.index) 100 else 0;

    But now I think about the following: what if I have not only eight layers, but more. Is there a way to find it out by expression(or set the maximum number automatically)?

    Like this: Math.floor(clamp(value,2,MaxValue));

    I read something about try/catch, does this work or is there another way to achieve this?

    Yours, Matthias

  • Kevin Camp

    November 7, 2017 at 12:01 am

    thisComp.numLayers will return the number of layers in the comp.

    Kevin Camp
    Art Director

  • Matthias Schwarz

    November 8, 2017 at 1:38 pm

    Wow, that works fine!

    I´ll start to learn now all the different commands, it´s very exciting. But one last question about this particular case.
    When I put all the pictures in a pre-comp, for the sake of usability(e.g. put more/other pictures inside)-is there a way(I guess so) to let the code

    if (thisComp.layer(“Controller”).effect(“Slider”)(“Schieberegler”) == thisLayer.index) 100 else 0;

    work “global” in the precomp without the need to copy this expression to all the opacity-properties in the pre-comp?
    It should work if there is a way to give it a name, I guess, e.g. “pre-comp.layer” instead of “thisComp.layer”. Does this work? I´ve learned Basic and TurboPascal 20 years ago but there are only a few similarities between JavaScript and these “old school” languages. So I try to understand, but every hint like yours here are so precious for me…

    Yours, Matthias

  • Kevin Camp

    November 8, 2017 at 6:25 pm

    you’ll have to have the expression on each layer that you want to be controlled by the slider. however there is an easy way to do that.

    select a layer that has the expression and type ‘t’ on the keyboard to reveal the opacity property. right-click the opacity property and choose ‘copy expression only’.

    then select all the layers that you want to use that expression and paste. now all those layers will have the same expression, and since your expression is referencing each layer’s unique index number, you should be good to go.

    Kevin Camp
    Art Director

  • Matthias Schwarz

    November 8, 2017 at 11:57 pm

    That´s a good way to safe time! So that´s enough knowledge for the moment. I thank you so much for all the time you spent on helping me! All thumbs up!

    Yours, Matthias

  • fabiano noli

    November 17, 2019 at 12:15 am

    Hi Kevin,
    sorry for the trouble,
    I have a question for this thread. I use AECC2017 and I copy your script, and this works great!
    So, I want that the opacity of my Precomp is “turn on” if the slider is less or equal of 0,02 and I used your Script like this:

    ctrl = thisComp.layer(“Master”).effect(“Slider Control”)(“Slider”);
    if ( Math.floor( ctrl ) <= 0,02 ) 100 else 0;

    but still not work !
    Can you help me?
    Thanks for your time

  • Markus Hahne

    December 16, 2019 at 10:17 pm

    Hi! Two things to solve this:
    1. The decimal uses dots, not commas. So it should be <= 0.02

    2. Since the new JavaScript engine is implemented you have to use more strict coding:
    if ( Math.floor( ctrl ) <= 0.02 ) {100} else {0};
    Another solution is to change back to the Legacy ExtendScript in the project settings and it will work without the curly brackets.

    Best wishes

Viewing 1 - 9 of 9 posts

Log in to reply.

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