Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions combining multiple if else statements

  • combining multiple if else statements

    Posted by Adam Greenberg on April 26, 2023 at 1:55 pm

    Hi all, I thought I saw this posted here, and I searched I cannot find it, but is there a way to rewrite this expression in a better way ( but not using an index method just in case the order of things gets changed ) .

    I thought a ternary operator would maybe save some lines if i set some variables first.

    there are 6 layers in a composition and i want the position in a different composition to change based on which precomp the user has turned on.

    thanks so much

    if(comp(“EDIT”).layer(“1”).active) -133.2; else

    if(comp(“EDIT”).layer(“2”).active) -57.2; else

    if(comp(“EDIT”).layer(“3”).active) -15.2; else

    if(comp(“EDIT”).layer(“4”).active) 61.2; else

    if(comp(“EDIT”).layer(“5”).active) 61.2; else

    179.2

    Adam Greenberg replied 3 years ago 2 Members · 2 Replies
  • 2 Replies
  • Dan Ebberts

    April 26, 2023 at 3:09 pm

    I might do it like this, but it doesn’t really save much unless you added more layers:

    L = [  "1",    "2",    "3",  "4",  "5"];
    V = [-133.2, -57.2 , -15.2, 61.2, 61.2];
    val = 179.2;
    for (i = 0; i < L.length; i++){
    if (comp("EDIT").layer(L[i]).active){
    val = V[i];
    break;
    }
    }
    val
  • Adam Greenberg

    April 26, 2023 at 5:09 pm

    Thanks Dan !!!

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