Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Switch between a number of layers with slider control

  • Switch between a number of layers with slider control

    Posted by Moog Gravett on April 5, 2016 at 2:08 pm

    Hi folks,

    hope someone can help me here.

    I want to partially automate some layer switching but can only find how to do it between two layers thus far.

    I want to have, lets say 5 (but ideally scaleable) layers that I can switch on and off with a 1-5 value on a slider control. Or some other animatable solution of course.

    Any ideas?

    Cheers,

    Moog

    Moog Gravett replied 10 years, 3 months ago 3 Members · 4 Replies
  • 4 Replies
  • Jakob Wagner

    April 5, 2016 at 2:36 pm

    Hi

    1. Create the five layers. 😉

    2. Create a null and rename it to “control”.

    3. Create a expression control slider on the null.

    4. Rename the slider to “Turnus”.

    5. Insert this code in the Opacity property in all the five layers:


    var totalLayers = 5;
    var layerIndex = 0;
    var visible = thisComp.layer("control").effect("Turnus")("Slider")>100/totalLayers*layerIndex;
    opacity = visible?100:0;

    6. Layer index on the first layer is 0. Next layer is 1, etc..

    Drag/animate the slider from 0 to 100.

    Hope it helps.

    – Jakob Wagner

  • Moog Gravett

    April 5, 2016 at 3:12 pm

    Hi Jakob,

    Thanks very much for your quick reply.
    I gave it a try but as I have it at the moment, the layers aren’t switching, rather it stays on one layer (the one highlighted in the screen grab). Would you mind taking a look to see what I’m doing wrong?

    Cheers,

  • Miguel De mendoza

    April 5, 2016 at 4:11 pm

    Maybe this ocurs because the slider have coma values(1.3, 2.7)and when interpolating cant find a 1.3 layer. So you can try to floor the slider value, to make this code work you only have to add to your layers name an index sufix “_1”, “_2”, etc…:

    sliderValue = //Your link to the slider
    nameSplit = name.split("_"); //
    shapeNum = nameSplit[nameSplit.length - 1];

    if (shapeNum == Math.floor(sliderValue)) {
    value = 100;
    } else {
    value = 0;
    }

  • Moog Gravett

    April 5, 2016 at 4:34 pm

    Brilliant!

    Thanks Miguel, that did the job beautifully.

    All the best and thanks to you both for taking the time to help.

    Moog

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