ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Measure only the width of a text layer using SourceRectAtTime

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Anne Blaak
Measure only the width of a text layer using SourceRectAtTime
on Mar 14, 2018 at 12:36:24 pm
Last Edited By Anne Blaak on Mar 14, 2018 at 3:52:17 pm

Hi all,

I try to make a template with the source text from the comp name and bars behind the text. The bars must be the same width as the text, but the height of the bars must be fixed.

Because the characters vary in height, the bars now also get a different height and it looks messy.
Is there a way to give the bars a fixed height without loosing the measured with?

The problem:


Shape size code:
t = thisComp.layer("text1");
tRect = t.sourceRectAtTime(time,false);
tUL = t.toComp([tRect.left,tRect.top]);
tLR = t.toComp([tRect.left+tRect.width,tRect.top+tRect.height]);
myRect = sourceRectAtTime(time,false);
myUL = toComp([myRect.left,myRect.top]);
myLR = toComp([myRect.left+myRect.width,myRect.top+myRect.height]);
margin = 14;
[(tLR[0]-tUL[0] + 2*margin),(tLR[1]-tUL[1]+ 2*margin)]


Shape position code:
t = thisComp.layer("text1");
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


Return to posts index

Dan Ebberts
Re: Measure only the width of a text layer using SourceRectAtTime
on Mar 14, 2018 at 4:20:19 pm

You could try something like this for the shape size:

t = thisComp.layer("text1");
myHeight = 50;
tRect = t.sourceRectAtTime(time,false);
margin = 14;
[tRect.width + 2*margin, myHeight]


Adjust myHeight to fit your situation.

Dan



Return to posts index

Anne Blaak
Re: Measure only the width of a text layer using SourceRectAtTime
on Mar 15, 2018 at 9:00:25 am

YASSS it works! Thank you so much!


Return to posts index

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