ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

How to override Out of Range error in an expression

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Mikael Holmström
How to override Out of Range error in an expression
on Mar 9, 2017 at 1:53:52 pm

Hi everyone,

I want to to use, for instance, the sourceRectAtTime(time).width value from the same layer index in another comp:

w = comp(”Another Comp").layer(index).sourceRectAtTime(time).width;

This work fine as long as the corresponding layer in the other comp a) exists b) is able to return the kind of value I'm asking for. I. e. it has to be at text layer. Otherwise it will cause an out of range error.

My question is:
How do i ”test” if there will be an error before it is executed, so I can avoid it with a simple if..then..else like:

if (comp(”Another Comp").layer(index).sourceRectAtTime(time).width=ERROR) {do nothing} else {do this and that}

Thank you!
Mikael


Return to posts index

Dan Ebberts
Re: How to override Out of Range error in an expression
on Mar 9, 2017 at 2:15:16 pm

try/catch should work:


try{
w = comp("Another Comp").layer(index).sourceRectAtTime(time).width;
}catch(err){
// do something else here
}


Dan



Return to posts index

Mikael Holmström
Re: How to override Out of Range error in an expression
on Mar 9, 2017 at 2:51:22 pm

Thanks! That solves the out of range issue. But now I see that sourceRectAtTime() is not only a property of text layers. Is there a way to determine if a layer is a text layer?
Mikael


Return to posts index


Dan Ebberts
Re: How to override Out of Range error in an expression
on Mar 9, 2017 at 4:49:23 pm

I guess you could include something like this in your try/catch:

try{
temp = comp("Another Comp").layer(index).text.sourceText;
w = comp("Another Comp").layer(index).sourceRectAtTime(time).width;
}catch(err){
// do something else here
}


Dan



Return to posts index

Mikael Holmström
Re: How to override Out of Range error in an expression
on Mar 9, 2017 at 6:32:05 pm

Brilliant. Absolutely brilliant.
Thanks
Mikael


Return to posts index

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