Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions if-else ‘check’ (sorta like if-exists?)

  • if-else ‘check’ (sorta like if-exists?)

    Posted by Ben Jordan on May 25, 2012 at 2:18 am

    I’m new to expressions, and am trying to have a “check” where if a certain layer exists, then the expression proceeds one way, if not, it does another thing.

    I don’t think there is a specific “ifexists” command, so I’m just checking the contents of a layer of text- right now I have a text layer called CHECK and its text is 1 (if I want it true), and if true, it uses the SCALE layer’s text for an expression.

    Ideally I’d like to just check if SCALE layer exists at all, and if so, use it… if not use other. I’m hoping for a better way to do this. Thanks for looking.

    if (thisComp.layer("CHECK").text.sourceText.toString()=="1" ){
    expr = thisComp.layer("SCALE").text.sourceText.toString()
    }else{
    expr = comp("MASTER CHIEF").layer("SCALE").text.sourceText.toString()
    }

    eval(expr)

    Ben Jordan replied 13 years, 11 months ago 2 Members · 2 Replies
  • 2 Replies
  • Dan Ebberts

    May 25, 2012 at 3:18 am

    I think this will do what you want:


    try{
    thisComp.layer("SCALE").transform.scale;
    }catch(err){
    comp ("MASTER CHIEF").layer("SCALE").transform.scale;
    }

    Dan

  • Ben Jordan

    May 25, 2012 at 5:11 am

    Cool, using the err catch works well. Thank you! …Learning how expressions work compared to PHP & AHK. 🙂

    I’m still pulling in the text source though, since the source has some larger expressions it’s pulling in to adjust things. But now I can adjust each seq ‘locally’ by dropping in certain layers (I have a dozen or so of these for different things) or globally by removing them. Here’s what I changed it to:

    try{
    expr = thisComp.layer("SCALE").text.sourceText.toString();
    }catch(err){
    expr = comp("MASTER CHIEF").layer("SCALE").text.sourceText.toString();
    }

    eval(expr)

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