FORUMS: list search recent posts

if-else 'check' (sorta like if-exists?)

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Ben Jordan
if-else 'check' (sorta like if-exists?)
on May 25, 2012 at 2:18:36 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)


Return to posts index

Dan Ebberts
Re: if-else 'check' (sorta like if-exists?)
on May 25, 2012 at 3:18:01 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



Return to posts index

Ben Jordan
Re: if-else 'check' (sorta like if-exists?)
on May 25, 2012 at 5:11:46 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)


Return to posts index

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