Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions IF – AND – THEN expression

  • IF – AND – THEN expression

    Posted by Jim Lefevre on March 9, 2012 at 12:54 pm

    apologies if this is an old old question. I *did* try and search for “if and then expression” but you’d be surprised about how many people use the words ‘if’ ‘and’ and ‘then’. Hmmm

    ANyhow!

    I have a 2D layer (MOON_MASK) and 3D layer which revolves (MOON_REVOLVE).

    I want MOON_MASK opacity to be 100 when MOON_REVOLVE’s Y rotation is between 0 and 180 and to be 0 when MOON_REVOLVE’s Y is between 181 and 360.

    Fine, easy, here’s what’s working

    maskOp = thisComp.layer(“MOON_REVOLVE”).transform.orientation[1];
    if (maskOp < 180){
    [100];
    }else{ [0] ; }

    However I’ve just realised I actually need the MOON_MASK opacity to be 100 between MOON_REVOLVE’s y value being 90 and 270 and for the life of me I can’t figure out the grammar to get an AND statement in there.

    Essentially what I want to say is

    maskOp = thisComp.layer(“MOON_REVOLVE”).transform.orientation[1];
    if (maskOp > 90) AND (maskOp <270){
    [100];
    }else{ [0] ; }

    but that’s obviously not happening!!

    I’m actually sure there might be a more elegant way through it anyway but even if there is, does After Effects do if/and statments?

    Many many thanks in advance for your help (anyone!!!)

    as ever

    Jim

    http://www.jimlefevre.com

    Dan Ebberts replied 9 years, 9 months ago 6 Members · 8 Replies
  • 8 Replies
  • Jim Lefevre

    March 9, 2012 at 1:37 pm

    Aaaaahhhh… ok… after some more digging and help from a colleague here at work I’ve stumbled up this!…

    maskOp = thisComp.layer(“MOON_REVOLVE”).transform.orientation[1];
    if (maskOp > 90 && maskOp <270){
    [0];
    }else{ [100] ; }

    so there you have it!

    &&

    works a treat!

    http://www.jimlefevre.com

  • Darby Edelen

    March 9, 2012 at 4:33 pm

    [jim lefevre] “maskOp = thisComp.layer(“MOON_REVOLVE”).transform.orientation[1];
    if (maskOp > 90) AND (maskOp <270){
    [100];
    }else{ [0] ; }”

    if((maskOP > 90)&&(maskOp < 270))

    The && is an operator that will return true only if the statements on both sides evaluate to true.

    There is also the || operator which will return true if one of the statements on either side is true (the ‘OR’ operator).

    If you’re doing this to make the layer invisible when pointing away from the camera there’s a better solution:

    https://motionscript.com/design-guide/invisible-facing-away.html

    Darby Edelen

  • Jim Lefevre

    March 14, 2012 at 8:16 am

    Darby,

    Thank you so much!

    Yes, I’d actually forgotten about that pointing away from camera thing although actually it wasn’t what I needed as I ended up needing layers to be visible for only a quarter of a revolution – 90 degrees – and not the 180 that that gives.

    More importantly what you’ve suggested is far more valuable as an introduction to the && and || operators ( although it’s taken me a fair few minutes to find the ‘|’ key on my keyboard (upper case ” if anyone is interested)!!

    I shall start to experiment and see how stackable they are too.

    Many many thanks Darby and apologies for the late reply – sudden deadline swamped me.

    http://www.jimlefevre.com

  • Bevis Lowry

    February 14, 2016 at 1:59 pm

    Hi guys.
    I wonder if you could help me with a related question. I’m quite new to scripting.
    I’m trying to do something similar to if/else but with gradations in between.
    It goes something like this:
    If Object A has Y coordinate 600, the scale Object B to 20.
    If Object A has Y coordinate 300, then scale Object B to 100.

    Now here’s the bit I can’t figure out:
    If Object A’s Y coordinates are between 300 and 600, then scale Object B between 20 and 100

    Any ideas would be appreciated 🙂

  • Kalleheikki Kannisto

    February 14, 2016 at 8:01 pm

    expression for object B scale:

    y= thisComp.layer("A").transform.position[1];
    s = linear(y,300,600,100,20);
    [s,s]

  • Bevis Lowry

    February 15, 2016 at 7:47 am

    Thanks Kalle. It worked great. I just had to reverse the 100 and the 20 🙂

  • Max Motionmoustache

    August 2, 2016 at 10:18 pm

    I got this formula in my position expression panel: if(thisComp.layer(“Control”).effect(“Man scale”)(“Slider”)=73) [441.1,-108,3] else [507.1,-108,3];
    I want the position that I sued expression on, to change to the values I have given to it when other layer’s slider control is at 73 one position and when it moves other position property. But I haven’t used IF expression before in AF, mby i’m applying it to the wrong property, i’m not sure. Gives an error.
    Or I thought to make the pickwhipe forumla, but forgot algebra from school =) to make basically position property X depend on anothe slider property. bullet points of that formula are
    (property X)=441,1 when slider = 73
    and
    (property X)=507,1 when slider = 453
    so expression for position like
    value[Z+H*slider value,0];
    Z and H are unknown

    made if expression by https://www.premiumbeat.com/blog/use-ifelse-statements-effects/ but didn’t work out basically..

    if(thisComp.layer("Control").effect("Man scale")("Slider")=73) [441.1,-108,3] else [507.1,-108,3];

  • Dan Ebberts

    August 3, 2016 at 6:20 am

    One thing I see is that JavaScript’s equality test is:
    ==
    not:
    =

    Dan

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