ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Finding the edges of text and shape layers just got a lot easier

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Dan Ebberts
Finding the edges of text and shape layers just got a lot easier
on Dec 17, 2014 at 10:17:12 pm

With the latest AE release (CC 2014.2) expressions now have a long-awaited feature that allows them to find the edges of text and shape layers without having to do the sampleImage() hack. It's sourceRectAtTime(), and it works the same as it does in scripting. Here are some general purpose examples for aligning a layer with the left, right, top, and bottom edges of a text layer:

// right edge

gap = 10;
L = thisComp.layer("some text");
r = L.sourceRectAtTime(0,true);
x = L.position[0] + (r.left + r.width - L.anchorPoint[0])*L.scale[0]/100 + scale[0]*width/200 + gap;
[x, value[1]]


// left edge

gap = 10;
L = thisComp.layer("some text");
r = L.sourceRectAtTime(0,true);
x = L.position[0] + (r.left - L.anchorPoint[0])*L.scale[0]/100 - scale[0]*width/200 - gap;
[x,value[1]]


// top edge

gap = 10;
L = thisComp.layer("some text");
r = L.sourceRectAtTime(0,true);
y = L.position[1] + (r.top - L.anchorPoint[1])*L.scale[1]/100 - scale[1]*height/200 - gap;
[value[0],y]

// bottom edge

gap = 10;
L = thisComp.layer("some text");
r = L.sourceRectAtTime(0,true);
y = L.position[1] + (r.top + r.height - L.anchorPoint[1])*L.scale[1]/100 + scale[1]*height/200 + gap;
[value[0],y]


Dan



Return to posts index

Tiago Cav
Re: Finding the edges of text and shape layers just got a lot easier
on Jun 1, 2015 at 12:18:12 pm
Last Edited By Tiago Cav on Jun 1, 2015 at 12:20:15 pm

Hey Dan, i have a problem, and is related to the Text "Anchor Point" Alignment.

With "sourceRectAtTime()" expression, between a Shape and a Text.

I need that the Text always stayed on top of the Shape, but as the expression is very sensitive to the letters, variations occur, and make the text is misaligned.

I can post a link of Adobe Forum here?
To show my problem with more details.

Thanks.


Return to posts index

Dan Ebberts
Re: Finding the edges of text and shape layers just got a lot easier
on Jun 1, 2015 at 6:59:49 pm

I posted something in the other forum--hope it helps.

Dan



Return to posts index


Tiago Cav
Re: Finding the edges of text and shape layers just got a lot easier
on Jun 2, 2015 at 4:06:53 am
Last Edited By Tiago Cav on Jun 2, 2015 at 4:09:58 am

Thank you, Dan!


Return to posts index

Adam Hannis
Re: Finding the edges of text and shape layers just got a lot easier
on Jun 6, 2018 at 11:31:17 am

Hi Dan,

This works really well, thank you for sharing!

I was wondering if it was possible to align a layer to the top/right using these examples?

I've tried combining the top edge and right edge code but I'm a beginner when it comes to expressions so haven't had much luck.

Many thanks,
Adam


Return to posts index

Dan Ebberts
Re: Finding the edges of text and shape layers just got a lot easier
on Jun 6, 2018 at 5:16:07 pm

Upper right corner would be something like this:

gap = 10;
L = thisComp.layer("some text");
r = L.sourceRectAtTime(0,true);
x = L.position[0] + (r.left + r.width - L.anchorPoint[0])*L.scale[0]/100 + scale[0]*width/200 + gap;
y = L.position[1] + (r.top - L.anchorPoint[1])*L.scale[1]/100 - scale[1]*height/200 - gap;
[x, y]


Dan



Return to posts index

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