Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions if/else/while etc

  • Posted by John Madison on January 26, 2011 at 7:23 pm

    Hi guys,

    I need your help on this.
    I have a layer which i intend to duplicate (in excess of 50 times) and using an expression, distribute them on the y axis according to the layers’ index value (i.e value+[0,index*5]). This is the easy part!

    I also have a slider control on another layer and want to use it to control the duplicated layers’ opacity (0/100 – i.e off/on). It should work like this:
    All the duplicated layers are off (in terms of thier opacity) unless the slider value is greater than 1. At which point, only the duplicated layer whose index value is between 2-6 is set to on (i.e. 100). If the slider value is greater than 2, then those whose index value is between 7-10 is ALSO on. Thus with every increment in the slider a further four layers are turned on. Do you see it?

    I can add a simple expression on each of the duplicated layers to achieve this effect. However, i want to write an expression on just the first layer so that i can then duplicate it without having to write an expression on each of the dupliated layers manually.

    Thanks.

    Kevin Camp replied 15 years, 3 months ago 2 Members · 5 Replies
  • 5 Replies
  • Kevin Camp

    January 26, 2011 at 9:08 pm

    something like this may work… it does assume that all layers are consecutive and the first layer has an index of 1, so your slider should be on a layer at the bottom of the stack (or directly on the first layer, i suppose)…

    ctrl = thisComp.layer("Null 1").effect("Slider Control")("Slider"); // this should be your slider ctrl
    if (ctrl < Math.ceil(index/4)) 0 else 100

    Kevin Camp
    Senior Designer
    KCPQ, KMYQ & KRCW

  • John Madison

    January 28, 2011 at 2:40 pm

    Hey Kevin,

    AE gives an error. Says ‘)’ expected in line 2. I’m on CS4 if that makes a difference. Also, if its not too much to ask, can you explain the properties you’ve used, or at least direct me to where i can better understand what the expression is doing.

  • Kevin Camp

    January 28, 2011 at 10:35 pm

    i’m really sorry about that… expression code input for the forum replaced the less-than symbol with the html equivalent, making the expression useless:

    hopefully a pre-formated tag will fix it:

    ctrl = thisComp.layer("Null 1").effect("Slider Control")("Slider"); // this should be your slider ctrl
    if (ctrl < Math.ceil(index/4)) 0 else 100

    it does a comparison between the slider value and the layer’s index (with a little math), if that value is less than the slider, the the opacity is 0, if it is greater than, or equal to, the slider then it is 100.

    Math.ceil() essentially rounds any decimal value up to the nearest whole value. so, index divided by 4 will always return a whole number… so in the case of indexes between 1 and 4, the value would be 1, and when 1 is not less than a slider value of 1, the first for layers should have the opacity of 100. for indexes 5-8, the value would be 2, so while the 2 is greater than the slider value, those layers have 0 opacity, when the slider reaches 2, then those layers will 100 opacity.

    Kevin Camp
    Senior Designer
    KCPQ, KMYQ & KRCW

  • John Madison

    January 29, 2011 at 7:56 pm

    Thanks a bunch Kevin. The only thing is my layer actually starts off as 3 for its index value as i need to have two layers above it.

  • Kevin Camp

    January 31, 2011 at 3:57 pm

    you just need to subtract the number of layers above the first layer from the index. so something like this should work:

    if (ctrl < Math.ceil((index-2)/4)) 0 else 100

    if you wanted to have the flexibility to add more layers above these, you could link the expression to a layer that you would always have just above the series of duplicates…

    startIndex = thisComp.layer("Null 2");  // the layer that will always be above the duplicates
    ctrl = thisComp.layer("Null 1").effect("Slider Control")("Slider"); // this should be your slider ctrl
    if (ctrl < Math.ceil((index-startIndex.index)/4)) 0 else 100

    Kevin Camp
    Senior Designer
    KCPQ, KMYQ & KRCW

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