Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions If else loop not working in Text Source

  • If else loop not working in Text Source

    Posted by Bryan Woods on January 12, 2017 at 12:06 am

    Trying to create an error dialogue for a template using a text layer that appears if a critical layer is missing.

    Currently I have this:

    BG = "Background_Layer missing";
    PoV = "PoV_Mover missing";

    if(thisComp.layer("Background_Layer") == null){
    BG;
    }else if(thisComp.layer("PoV_Mover") == null){
    PoV;
    }else{
    "ERROR";
    }

    When I delete one of the critical layers, the text source only displays whats input into the text source not dynamically based on the condition like I want. Any ideas?

    Bryan Woods replied 9 years, 6 months ago 2 Members · 4 Replies
  • 4 Replies
  • Dan Ebberts

    January 12, 2017 at 12:27 am

    There are probably better ways, but I’d try something like this:


    BG = "Background_Layer missing";
    PoV = "PoV_Mover missing";
    msg = "";

    try{
    temp = thisComp.layer("Background_Layer");
    }catch (e1){
    msg = BG;
    }

    try{
    temp = thisComp.layer("PoV_Mover");
    }catch (e2){
    msg = PoV;
    }
    msg

    Dan

  • Bryan Woods

    January 12, 2017 at 12:31 am

    Interesting. So that does work, but I want to know why. Is it an order of operations thing between if/else and try{catch}, where try is processed before a typical if/else loop would?

    Thanks for the help Dan. Glad to see a familiar face still here.

  • Dan Ebberts

    January 12, 2017 at 12:34 am

    Referencing a layer that doesn’t exist generates an expression error, try/catch traps such an error. That’s about it.

    Dan

  • Bryan Woods

    January 12, 2017 at 12:55 am

    Ah, makes sense. Thanks for the explanation.

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