Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions try catch(err) for sourceRectAtTime expression

  • try catch(err) for sourceRectAtTime expression

    Posted by Alex Andry on January 17, 2021 at 7:33 pm

    Hi guys, the scale expression shows an error if no text is entered or there are only spaces instead of characters.
    How to catch errors so that in these cases the values are equal [0,0]?

    R = sourceRectAtTime(sourceTime(time), true);

    w = thisComp.width / R.width * 95;

    h = thisComp.height / R.height * 60;

    s = Math.min(w, h);

    [s, s]

    Thanks in advance!

    Alex Andry replied 5 years, 4 months ago 2 Members · 2 Replies
  • 2 Replies
  • Andrei Popa

    January 18, 2021 at 9:19 am

    You need to use an exception for when it’s zero because you can’t divide by 0. Try this

    R = sourceRectAtTime(sourceTime(time), true);

    w = R.width == 0 ? (thisComp.width / R.width) * 95 : 0;

    h = R.height == 0 ? (thisComp.height / R.height) * 60 : 0;

    s = Math.min(w, h);

    [s, s];

  • Alex Andry

    January 18, 2021 at 9:40 am

    Hi Andrei, this works great! Thank you very much!

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