Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Self-resizing box – multiple boxes

  • Self-resizing box – multiple boxes

    Posted by pav kun on December 9, 2021 at 1:22 pm

    Hi all,

    I need some guidance how to best resize multiple boxes based on text length. I am rather new to expressions, and I was wondering if someone could help out with some fairly basic automation.

    In my comp I have a self-centered text and a box around it that resizes to the text length (let;s call it ‘Box1’). Box 1 has expression to get position and size based on text layer width and height.

    I would like to be able to set up ‘Box 2’ which will always have a fixed width but it’s height is the same as Box1.

    And finally, create a simple shape that will sit in the center of Box2.

     

    So far I have this JS for Box1-

    Size :

    margin=20;

    text_width = thisComp.layer(“Text”).sourceRectAtTime().width;

    text_height = thisComp.layer(“Text”).sourceRectAtTime().height;

    box_width = text_width + margin*2;

    box_height = text_height + margin*2;

    [box_width, box_height]

    pos:

    text_height = thisComp.layer(“Text”).sourceRectAtTime().height;

    [0, text_height/2]

    transform-pos:

    t = thisComp.layer(“Text”);

    tRect = t.sourceRectAtTime(time,false);

    tUL = t.toComp([tRect.left,tRect.top]);

    tLR = t.toComp([tRect.left+tRect.width,tRect.top+tRect.height]);

    tCenter = (tUL + tLR)/2

    myRect = sourceRectAtTime(time,false);

    myUL = toComp([myRect.left,myRect.top]);

    myLR = toComp([myRect.left+myRect.width,myRect.top+myRect.height]);

    myCenter = (myUL + myLR)/2

    delta = myCenter – tCenter;

    value – delta

     

     

    Any hints on how to best set up box 2 position would be greatly appreciated.

    Graham Quince replied 4 years, 9 months ago 2 Members · 1 Reply
  • 1 Reply
  • Graham Quince

    December 11, 2021 at 3:11 pm

    I made a similar-ish resiving pop up for my videos and had to add some maths to the Position and anchor points of the box. With the anchor always being central to the shape layer, you have to shift it’s position by half the width (sort of).

    Here’s my tutorial, which includes the expressions code:

    https://youtu.be/cobn_x6tqHc

    Some contents or functionalities here are not available due to your cookie preferences!

    This happens because the functionality/content marked as “Google Youtube” uses cookies that you choosed to keep disabled. In order to view this content or use this functionality, please enable cookies: click here to open your cookie preferences.

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