Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity › Forums › Adobe After Effects Expressions › Scaling size restrictions including a failsafe for 0

  • Scaling size restrictions including a failsafe for 0

    Posted by Tiffany Gregg on June 29, 2021 at 12:26 am

    I’m building a spreadsheet driven template. I use this expression to limit the size of a layer (often text,) but since there won’t always be data that fills this layer, sometimes the sourceRectAtTime will come back 0, which breaks the expression when it tries to divide by zero and turns it off for subsequent renders that will need it active. I figured I would have to include a conditional that if r==0 then it should have some arbitrary size like 100, but nothing I’ve tried is getting me results. Where/how would I add this?

     

    maxW = thisComp.width*0.85;

    maxH = thisComp.height*0.075;

    r = sourceRectAtTime(time);

    w = r.width;

    h = r.height;

    s = w/h > maxW/maxH ? maxW/w : maxH/h;

    [100,100]*s;

     

    any assistance would be greatly appreciated!

    Tiffany Gregg replied 5 years, 2 months ago 2 Members · 2 Replies
  • 2 Replies
  • Dan Ebberts

    June 29, 2021 at 12:56 am

    Something like this should work:

    maxW = thisComp.width*0.85;

    maxH = thisComp.height*0.075;

    r = sourceRectAtTime(time);

    w = r.width;

    h = r.height;

    if (w > 0 && h > 0){

    s = w/h > maxW/maxH ? maxW/w : maxH/h;

    }else{

    s = 1;

    }

    [100,100]*s;

  • Tiffany Gregg

    June 29, 2021 at 12:46 pm

    Thank you so much! I always struggle adding a conditional to an existing expression. You are amazing, I’m honored!

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