ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Using sourceRectAtTime(); to link two boxes together

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Donald Chinkeret
Using sourceRectAtTime(); to link two boxes together
on Nov 13, 2019 at 12:02:43 am

I have 4 layers that make up a lower third.
Name, Title, Name Box, Title Box

In Name Box, under contents>rectangle 1>rectangle Path 1>Size I have this expression:
title=thisComp.layer("NAME").sourceRectAtTime();
L=effect("Length")("Slider");
H=effect("Height")("Slider");
[title.width+L, title.height+H]

(the sliders are there to give padding around the text)

Under contents>rectangle 1>rectangle Path 1>Position I have this expression:
content("Rectangle 1").content("Rectangle Path 1").size/2

(This is to keep things left aligned)

The Title Box has the same expressions, but referencing the layer "title" instead of "name."

What I'm trying to do is link the position of Title Box to the Name Box so that as the Name Box gets taller or shorter, the Title Box will remain the same distance from the Name Box.

What expression can I use to do this?I know I need to use sourceRectAtTime to find the height of the first box and somehow tell the


Return to posts index

Andrei Popa
Re: Using sourceRectAtTime(); to link two boxes together
on Nov 13, 2019 at 7:45:41 am

I would try to align the anchor of the shape layers to left. Try using this script i made for anchor point placement.

Then add to the position the part of the sourceRectAtTime that you want. If you want one rectangle to be to the left of the other, then position should have something like this:

prevPosition = thisComp.layer("Rectangle 1"). position;
prevWidth = thisComp.layer("Rectangle 1").sourceRectAtTime(time,false).width;
[prePosition[0]+prevWidth, value[1]]


Similar to this, if you want them to be one under the other, you use the anchorPoint script. This is even easier. Set the anchorPoint to the top left for the bottom layer and bot left to the top layer. And let's say you want the bottom layer to be aligned vertically and with a 20 px space under the top. Top being Rectangle 1, this is the position expression:

prevPosition = thisComp.layer("Rectangle 1").position;
padding = 20;
[prevPosition[0]+padding, prevPosition[1]]


Andrei
My Envato portfolio.


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2019 CreativeCOW.net All Rights Reserved
[TOP]