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

After Effects Position Expression Help

New Here ,
Nov 10, 2018 Nov 10, 2018

Copy link to clipboard

Copied

Hey everybody, I am wondering if anyone in the forum has experience with messing around with expressions in After Effects. I needed to find a way to create self-resizing lower thirds so I looked up some tutorials on youtube that could help me. I managed to get the main header to work the way I wanted it. The problem is that I have to place a caption underneath the header (for example, HEADER: Chris Richards, Caption: Vice President). This composition is meant to be used as a template that can be edited in Adobe Premiere, so whenever someone would type a new name in, I would want the caption to be right aligned (flush right) under the name in the text box. My dilemma is that I don't know how to scribe an expression that would move the captions position in accordance with the finishing of the header. if anybody can help me out, I would greatly appreciate it. Attached are some images of the project file.Expression.pngScreen Shot 2018-11-10 at 3.46.39 PM.pngF3.pngF2.pngScreen Shot 2018-11-10 at 3.52.55 PM.png

Views

3.9K

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 ,
Nov 10, 2018 Nov 10, 2018

Copy link to clipboard

Copied

If you have a new enough version of After Effects you can use the sourceRecAtTime() method. It is fairly well explained here:

Evan Abrams | SourceRectAtTime() Expression- Adobe After Effects

I use a very similar technique but I add a bit to height and width to clean up the design and I'll also use a time offset to make the text box expand. I add a text animator to the text layer to make it fade on. Then I add a shape layer to the timeline above the text layer by double-clicking the tool then add two sliders, name them Padding and Offset, then I'll add this expression to the size of the rectangle:

pad = effect("Padding")("Slider");

ofst = effect("Offset")("Slider") / 100;

src =thisComp.layer(index + 1);

x= src.sourceRectAtTime(time-src.inPoint,true).width + pad;

y= src.sourceRectAtTime(time-src.inPoint,true).height + pad;

adj = src.text.animator("Animator 1").selector("Range Selector 1").start.valueAtTime(time + ofst)/100;

[x * adj, y]

You also add an expression to the Transform Rectangle 1>Anchor point to make the rectangle expand from the left. It looks like this:

x = content("Rectangle 1").content("Rectangle Path 1").size[0]/2;

[- x, value[1]]

The next step is to let the animation complete by going to the last Animator keyframe, position the text box over the text layer, adjust the Padding and then move back in time a bit and adjust the Offset to line the timing of the expanding text box up with the words as they animate on.

I hope that makes sense. Here's the animation preset that I have made to speed up the process: Dropbox - Auto Text background.ffx

All you have to do is download the preset, animate a text layer with left justified text, deselect the text layer and browse to the ahimation preset and run it. You will get a text layer that you can position over your text and then parent to the text layer. You'll get a comp that looks like this:

Screenshot_2018-11-10 15.08.43_UnuPIc.png

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
New Here ,
Nov 10, 2018 Nov 10, 2018

Copy link to clipboard

Copied

Hey Rick, thanks for the solution but it didn't really answer my question. I checked the Evan Abrams video because it is kind of an update to the expression I already used. I'm wondering if you know how I can have the position of my caption align with the end of my header even when I type a new name?

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
New Here ,
Nov 10, 2018 Nov 10, 2018

Copy link to clipboard

Copied

I managed to create an expression that allows me to have the caption move with the header. However, I think because the header uses a higher point size, the caption falls behind. I'm a complete newbie to expressions so I'm sorry if I don't understand some of the stuff you mention.

Screen Shot 2018-11-11 at 1.03.19 AM.pngScreen Shot 2018-11-11 at 1.03.24 AM.pngScreen Shot 2018-11-11 at 1.03.39 AM.png

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
LEGEND ,
Nov 11, 2018 Nov 11, 2018

Copy link to clipboard

Copied

Unless you've changed the anchor points, the 'origin' of a text layer is always the bottom left corner. You want the right side of your subtitle to line up with the right side of your title, so you simply calculate the width of each, subtract one from the other, and add the value to the X-position of the subtitle. You can get fancy and handle cases where the title is wider than the subtitle but the justification part is just basic math.

sourceRectAtTime().width gives you the width of the text "bounding box" at the current time. So;

  1. Assume your title layer is called "title".
  2. Left-align the title and subtitle layers, and make sure the subtitle paragraph mode is also left-justify.
  3. Parent 'subtitle' to 'title' so they move together.
  4. Put this into the position expression on the 'subtitle' layer

titleLayer = thisComp.layer("title");

titleWidth = titleLayer.sourceRectAtTime().width;

subWidth = sourceRectAtTime().width;

xOffset = titleWidth = subWidth;

[value[0]+xOffset,value[1]]

That last line just returns the original position as an [x,y] array with the position shifted to the right.

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 Expert ,
Nov 11, 2018 Nov 11, 2018

Copy link to clipboard

Copied

So let me get this straight. Here's what I think you want to accomplish:

  1. The graphic contains a name and title
  2. The title should line up with the right edge of the name
  3. You want the left position of the name to stay in the same place
  4. The text does not animate on (if it does we can fix that fairly easily)

If that is the case then the approach you start with left justified paragraph for the name and right justified paragraph for the title.

You can use sourceRecAtTime() to figure out where the right edge of the Name text is in relation to the position of the text layer. You can then take the position of the text layer and add the X value of the sourceRecAtTime method to the position of the title layer. Since the title is right justified it will grow to the left as you enter the name, and the Name layer will always grow toward the right.

When I'm writing expressions that involve two layers that should be placed right on top of each other I usually use index plus or minus 1 instead of the layer name so that you don't have to worry about naming layers. If you add a slider for the height difference between the layers everything should be fine. The Name layer can also be used to drive the size and even the position of the background layer. If you arrange the layers so the Solid background for the name is on the bottom, the name layer is next and the top layer is the title layer is on top you can easily create animation presets for both.

I would modify the expressions above a bit. Here's the one for the shape layer Rectangle 1>Size which includes a couple of sliders to control the margins of the background layer.

src = thisComp.layer(index - 1);

pad = effect("Pad")("Slider");

x= src.sourceRectAtTime(time-src.inPoint,true).width + pad;

y= src.sourceRectAtTime(time-src.inPoint,true).height + pad;

[x, y]

It's almost the same as the other one I posted.

The Transform Rectangle 1>Anchor point is a bit more complicated than the previous one:

rec = content("Rectangle 1").content("Rectangle Path 1").size;

pad = effect("Pad")("Slider")/2;

yt = effect("Y trim")("Slider");

xt = effect("x trim")("Slider");

x = - rec[0]/2;

y = value[1] + pad;;

[x + pad + xt, y - pad + yt]

I've added a Pad, Y trim, and X trim slider so you can accurately position the Rectangle for the background.

The other layer, the Title layer has one slider, Y trim, and this expression for Position:

src = thisComp.layer(index + 1);

op = position;

yt = effect("Y trim")("Slider");

x= src.sourceRectAtTime(time-src.inPoint,true).width;

y= src.sourceRectAtTime(time-src.inPoint,true).height;

[op[0] + x, op[1] + y + yt]

If you carefully look at the expressions you can figure out what they are doing.

The trick is to start with all layers in their default position, then parent the two text layers to the Background. Now you can position the title anywhere you like, the title will be at the bottom right corner of the Name layer, you can trim the Y offset to take into account the size of the background layer. As long as the layers are arranged in the right order and the paragraph styles are followed this should work just fine.

This whole thing can be added to an Essential Graphics template so you can use it in Premiere Pro to enter the names and title there.

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
LEGEND ,
Nov 11, 2018 Nov 11, 2018

Copy link to clipboard

Copied

I guess I don't get it.  It's a stinking lower-third!  How tough can it be to

1) figure out the vertical dimension it should be,

2) figure out how big the typeface can be for the name and

3) figure out the size of the typeface for the individual's title?

This is not rocket science, folks -- it's basic composition!

My God, I can not believe how LAZY people are becoming!

Someone tell me why I'm wrong.

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 Expert ,
Nov 11, 2018 Nov 11, 2018

Copy link to clipboard

Copied

If you want an extended graphics template that lines up the title on the right edge of the text and has a background, this is the efficient way to do it. If you are just doing one, then why bother.

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
New Here ,
Nov 11, 2018 Nov 11, 2018

Copy link to clipboard

Copied

LATEST

Can you explain a bit further?

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
New Here ,
Nov 11, 2018 Nov 11, 2018

Copy link to clipboard

Copied

Um I kinda found the solution through some other videos. if I can be honest, your solutions were more complex than what I needed but I understand that it's because I'm using an old method. Are there any websites where I can basically learn these expressions through tutorials or such, maybe like Codecademy?

Solution:

Add to the position of the caption...

title = thisComp.layer("Rectangle").sourceRectAtTime();

value + [title.width, 0]

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