Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions sourceRectAtTime

  • Posted by Saso Goricar on May 16, 2019 at 6:38 pm

    Hello,

    I have a problem with sourceRectAtTime expression. I would like to create a box around text, which always has an equal size on width and height. Basically, I want to create a square, which has the same width and height, when I type a different number or I a scale number.

    Picture of my comp: https://www.dropbox.com/s/vi3xgtxj86jpylb/AE-Box.PNG?dl=1

    As you can see, if I write down the number 1, width and height are not the same. Is it possible to always keep the same values for width or height?

    Thanks for the help,
    Saso

    Expression on size property:
    var s = thisComp.layer("1");
    var w = s.sourceRectAtTime().width;
    var h = s.sourceRectAtTime().height;
    [w,h]

    Saso Goricar replied 6 years, 11 months ago 3 Members · 4 Replies
  • 4 Replies
  • Miguel De mendoza

    May 16, 2019 at 7:20 pm

    Just use one of the dimensions:
    var s = thisComp.layer("1");
    var w = s.sourceRectAtTime().width;
    var h = s.sourceRectAtTime().height;
    [w,w]

  • Dan Ebberts

    May 16, 2019 at 7:23 pm

    Like this:

    var s = thisComp.layer(“1”);
    var r = s.sourceRectAtTime();
    var m = Math.max(r.width,r.height);
    [m,m]

    Dan

  • Saso Goricar

    May 16, 2019 at 7:29 pm

    Thanks for this trick, but if I write down a different number, two digits for example, I get a smaller box. Is it possible to make it dynamic, if I turn this into the .mogrt file to resize automatically?

    I get this: https://www.dropbox.com/s/o9e955qloa0o3f4/AE-Box-1.PNG?dl=1

    Thanks,
    Saso

  • Saso Goricar

    May 16, 2019 at 7:43 pm

    Thanks, Dan,

    that’s exactly what I was trying to achieve.

    I added additional slider control to adjust the margin. If you write a bigger number you could get too big box.
    https://www.dropbox.com/s/xahfqzd1e687zhb/AE-Box-2.PNG?dl=1

    Thanks again,
    Saso

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