Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions How to override Out of Range error in an expression

  • How to override Out of Range error in an expression

    Posted by Mikael Holmström on March 9, 2017 at 1:53 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

    Mikael Holmström replied 9 years, 4 months ago 2 Members · 4 Replies
  • 4 Replies
  • Dan Ebberts

    March 9, 2017 at 2:15 pm

    try/catch should work:


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

    Dan

  • Mikael Holmström

    March 9, 2017 at 2:51 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

  • Dan Ebberts

    March 9, 2017 at 4:49 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

  • Mikael Holmström

    March 9, 2017 at 6:32 pm

    Brilliant. Absolutely brilliant.
    Thanks
    Mikael

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