ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

If else loop not working in Text Source

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Bryan Woods
If else loop not working in Text Source
on Jan 12, 2017 at 12:06: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?


Return to posts index

Dan Ebberts
Re: If else loop not working in Text Source
on Jan 12, 2017 at 12:27:48 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



Return to posts index

Bryan Woods
Re: If else loop not working in Text Source
on Jan 12, 2017 at 12:31:19 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.


Return to posts index


Dan Ebberts
Re: If else loop not working in Text Source
on Jan 12, 2017 at 12:34:22 am

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

Dan



Return to posts index

Bryan Woods
Re: If else loop not working in Text Source
on Jan 12, 2017 at 12:55:34 am

Ah, makes sense. Thanks for the explanation.


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]