• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Auto-spacing text boxes

Community Beginner ,
Jan 05, 2023 Jan 05, 2023

Copy link to clipboard

Copied

I have text boxes that change size depending on how much text is inside of them. I want to set them up like a continuous "message" style animation, so there will be a lot of these boxes. The thing is, I want them to all be equally spaced out so that the top of each box is the same distance away from the box above it no matter how much text is in each box. 

My end goal is to prepare all the text boxes in advance, use a code to equally space them automatically so I don't have to do it manually, and connect them to a null object so I can move them up, resulting in the message style animation. I feel like the answer / code is pretty simple but I'm not too well-versed in AE code.

 

(I've also tried messing around with Align a bit but since the boxes will be going outside of the composition it's no use.)

TOPICS
Expressions , How to

Views

271

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 06, 2023 Jan 06, 2023

Copy link to clipboard

Copied

     

I would add an expression to the rectangle size and position property of a shape layer below the text layer. You use sourceRectAtTime() to look at the text layer above the shape layer using ref = thisComp.layer(index - 1). First, you want to calculate the size of the rectangle and maybe add a little padding;

 

// Rectangle 1/Size
ref = thisComp.layer(index - 1);
b = ref.sourceRectAtTime();
xPad = 40;
yPad = 30;
w = b.width;
h = b.height;
[w + xPad, h + yPad]

 

Next, you work on the shape layer's position property and add in b.top and b.left;

 

// Shape Layer position;
ref = thisComp.layer(index - 1);
rPos = ref.position;
b = ref.sourceRectAtTime();
w = b.width/2;
h = b.height/2;
t = b.top;
l = b.left;
x = w + l;
y = h + t;
[x, y] + rPos

 

Next, you duplicate the shape and text layers and move them to the top (Ctrl/Cmnd + d followed by Ctrl/Cmnd + [

 

You should now have. a text layer, a shape layer, another text layer, and another shape layer. The next thing you have to do is offset each text layer by the height of the next text layer. You can do this by using refT = thisComp.layer(index + 2); on the Position property of the succeeding text layers. You will have to find the in-point of each succeeding text layer by using sourceRectAtTime(inPoint) and an if/else statement to start moving each succeeding text layer up when the new pair of text and background layers start in the composition. Adding an ease(t, tMin, tMax, value1, value2) to the mix will move up each new text/shape layer pair up as each new pair is added to the composition.

 

I don't have time to write out that expression for you. It's going to be the hardest one to set up. When the text layer/position expression is worked out, every time a new pair is added to the comp, the pair of text/background layers above it will move up in the frame. 

 

I hope this gets you started. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 10, 2023 Jan 10, 2023

Copy link to clipboard

Copied

LATEST

Thank you so much for this! I've gotten to learn a lot more about expressions in After Effects. Just wondering, would this still work the same if I used the auto-spacing text box animation preset from Adobe Bridge?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines