Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions need to change the layer from an expression by changing the slider number

  • need to change the layer from an expression by changing the slider number

    Posted by Constanti Dinu on May 27, 2014 at 2:56 pm

    hey, i found myself in a bit of a problem here.
    i have a map with countries, each country is a layer on the map. now, for example:

    -i’ve got the opacity of Russia layer linked to the opacity of a layer named “position 1”.
    -i have another layer named “position 2”, somewhere on the timeline, at the middle of the animation.

    i want to put a slider where i can change the number from 1 to 2, and the opacity from Russa layer will be switched from the “position 1” layer opacity to “position 2” layer opacity.

    it should be something as:

    IN OPACITY PROPRETY:

    The number to change = thisComp.Layer(“got a slider here”).effect(“slider”);
    thisComp.layer(“position” + the number to change).transform.opacity

    i don’t know how to write the expression, so please, help.

    Constanti Dinu replied 11 years, 11 months ago 3 Members · 3 Replies
  • 3 Replies
  • Dan Ebberts

    May 27, 2014 at 4:43 pm

    It’s not too far from what you have:

    s = thisComp.layer(“got a slider here”).effect(“Slider Control”)(“Slider”);
    thisComp.layer(“position ” + Math.round(s)).transform.opacity

    Dan

  • Darby Edelen

    May 27, 2014 at 4:52 pm

    [constanti dinu] “The number to change = thisComp.layer(“got a slider here”).effect(“slider”);
    thisComp.layer(“position” + the number to change).transform.opacity”

    Have you tried using something like that?

    Of course you’d need to rewrite “The number to change” as an actual variable like “n” and “slider” as the name of the slider. You’ll also need to add a space after “position” to format the name of the layer correctly (“position 1” instead of “position1”). Lastly you’ll need to make sure that the slider value is an integer (e.g. 1 or 2 instead of 1.46213), but in essence I don’t see any reason why what you’ve spec’d out wouldn’t work. Here’s the code with my suggested modifications:

    x = Math.floor(thisComp.Layer("got a slider here").effect("Slider Control")("Slider"));
    thisComp.layer("position " + x).transform.opacity

    Optionally you might want to add some error checking in case the slider accidentally tries to select a layer that does not exist:


    try{
    x = Math.floor(thisComp.Layer("got a slider here").effect("Slider Control")("Slider"));
    thisComp.layer("position " + x).transform.opacity
    }
    catch(err){
    value;
    }

    Darby Edelen

  • Constanti Dinu

    May 29, 2014 at 8:47 am

    Thans a lot guys! worked like a charm

    while you were helping me with the answers, i got something similiar,like this:

    x=thisComp.layer(“got a slider here”).effects(“slider”)(1);
    y=parseInt(x);
    thisComp.layer(y).transform.opacity

    it worked, the only problem was that y was retrieveng the index number from the layer, which wasn’t the best way, since is pretty easy to add a new layer and mess everything up. i tried something similiar to what you have with “position “+x, but didn’t work. so thanks a lot

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