FORUMS: list search recent posts

How to use "sourceRectAtTime" expression with accents

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Sébastien Parrinello
How to use "sourceRectAtTime" expression with accents
on Sep 2, 2015 at 2:22:36 pm

Hi everyone !

First of all I have to say that I'm french so my English vocabulary is limited and that I'm not really good at scripting so...I'll try to be as explicit as I can.

Some weeks ago I was looking for a way to create some cool lower thirds in after effects and have them stretch up to fit automatically the text I want.
So I created my text and my background animation. I precomposed this background animation and add a corner pin on it and then used the very useful expression "sourceRectAtTime()" so that the animation fits the size of the text.

The idea was to be able to create multiple lower thirds by importing titles using the plugin "CompsFromSpreadsheet" and have my background animations to fit the size of the text in all comps.

This actually works pretty well. But I have one big problem (that makes me regret I wasn't born in an English speaking country)

As soon as my title contains an accent such as Â,Î, Ô, É, È... the size of the text layer obviously change and my text is no longer centered. The box streches from the bottom to fit the new size.

Here is a screencaps of the problem and the expressions associated with it.

creativecow_sourcerectaccent.jpg

I know I could just add the expression "sourceRectAtTime().height" to the top right corner of the corner pin effect by the other thing is that I'd like to be able to create texts with multiple lines.
I want my background to fit the size of the text even if this one contains accent and be able to add lines if I have to.

At work, we thought we could use two text layers, one with accents that defines the size of my background animation, and the other one with or without accents that is displayed. This is a workaround that would work but is there a way to remove accented letters with non accented letters automatically in After Effects ? (by using an expression?)

I've been searching for a solution but not any of the workarounds I thought of worked :/
I'd like to hear what you think about that and if you have any solution, I'll take it !

Thanks!

//So far these are the expressions I use on the corner pin effect of my background animation composition //

// Top left //

[effect("Quatre coins")("Supérieur gauche")[0],effect("Quatre coins")("Supérieur droit")[1]]

// Top right //

x=thisComp.layer("TITLE é").sourceRectAtTime().width;
[x,effect("Quatre coins")("Supérieur droit")[1]]

// Bottom left //

[effect("Quatre coins")("Supérieur gauche")[0],effect("Quatre coins")("Inférieur droit")[1]]

// Bottom right //

y=thisComp.layer("TITLE é").sourceRectAtTime().height;
[effect("Quatre coins")("Supérieur droit")[0],y]


Return to posts index

Dan Ebberts
Re: How to use "sourceRectAtTime" expression with accents
on Sep 2, 2015 at 5:51:54 pm

If you're using corner pin, I'd do something like this:

//upper left:

L = thisComp.layer("text");
r = L.sourceRectAtTime(time,false);
fromComp(L.toComp([r.left,r.top]))

// upper right:

L = thisComp.layer("text");
r = L.sourceRectAtTime(time,false);
fromComp(L.toComp([r.left+r.width,r.top]))

// lower left:

L = thisComp.layer("text");
r = L.sourceRectAtTime(time,false);
fromComp(L.toComp([r.left,r.top+r.height]))

// lower right:

L = thisComp.layer("text");
r = L.sourceRectAtTime(time,false);
fromComp(L.toComp([r.left+r.width,r.top+r.height]))


Dan



Return to posts index

Sébastien Parrinello
Re: How to use "sourceRectAtTime" expression with accents
on Sep 2, 2015 at 7:31:36 pm

Wow, it looks so simple...
It works like a charm thank you so much Dan ! It greatly simplyfies the expressions too.
I'm going to need some time to break down how you did this but that's great.

I have another question though. What if I'd like my lower thirds to have the exact same height wether their texts have accents or not.
I'll try to explain.
In our videos, we usually use a fade transition between sequences. It would be great to have the lower thirds all at the same height, accents or not.
That would of course mean that in the case of a title with no accents, the background animation would be larger in y and the text would be centered.
This is what I mean:

creativecow2.jpg

The thing is I still want to be able to add lines. Not sure it's possible.

Anyway, that's a really good solution you've helped me a lot !


Return to posts index


Dan Ebberts
Re: How to use "sourceRectAtTime" expression with accents
on Sep 2, 2015 at 7:58:45 pm

Here's a hack you can try. Pick a string that has the greatest y extents you might need ("Ég" in this example). Then add a source text expression like this to your text layer:

if (time < 0) "Ég" else value

Then modify your corner pin expressions like this:

// upper left

L = thisComp.layer("text");
r1 = L.sourceRectAtTime(-1,false);
r2 = L.sourceRectAtTime(time,false);
fromComp(L.toComp([r2.left,r1.top]))

// upper right

L = thisComp.layer("text");
r1 = L.sourceRectAtTime(-1,false);
r2 = L.sourceRectAtTime(time,false);
fromComp(L.toComp([r2.left + r2.width,r1.top]))

// lower left

L = thisComp.layer("text");
r1 = L.sourceRectAtTime(-1,false);
r2 = L.sourceRectAtTime(time,false);
fromComp(L.toComp([r2.left,r1.top + r1.height]))

// lower right

L = thisComp.layer("text");
r1 = L.sourceRectAtTime(-1,false);
r2 = L.sourceRectAtTime(time,false);


The expressions should pick up the max y dimensions by getting the sourceRect from a negative time, where the string is "Ég" (or whatever you set it to), but use the actual sourceRect to calculate the width.


Dan



Return to posts index

Sébastien Parrinello
Re: How to use "sourceRectAtTime" expression with accents
on Sep 3, 2015 at 8:41:13 am
Last Edited By Sébastien Parrinello on Sep 3, 2015 at 12:30:35 pm

The hack works really well in one text line and that's awesome but for some unknown reason (at least unknown to me) it doesn't work when I write on multiple lines.

EDIT: Problem solved, just need to remove r1 from lower left and lower right

I'm breaking down your expressions and learning more about toComp(), fromComp() and sourceRectAtTime() functions.
There is something I still don't understand.

I've seen that you used "r.left" and "r.top" to get the extreme left and top positions of the text bounding box. To get the right and bottom values, you used "r.left + r.width" instead of "r.right" (which seems not to exist). That's my question: why is it impossible to get the extreme right and bottom values of the bounding box directly by using "r.right" or "r.bottom" ?

Of course, "r.left+r.width" does the job but I'm curious to know why such function doesn't exist.

Again, Dan, thank you so much !


Return to posts index

Dan Ebberts
Re: How to use "sourceRectAtTime" expression with accents
on Sep 3, 2015 at 2:00:50 pm

>That's my question: why is it impossible to get the extreme right and bottom values of the bounding box directly by using "r.right" or "r.bottom" ?

I'm not sure why they did it that way originally, but the expressions implementation matches the way they did it with scripting (which came first).

Dan



Return to posts index


Sébastien Parrinello
Re: How to use "sourceRectAtTime" expression with accents
on Sep 4, 2015 at 9:05:50 am

Ok, I've been playing with these expressions for hours and it works great but in certain conditions.

Maybe I've started things the wrong way. The problem is the corner pin effect I think. When I want to add round corners to my shape layer in my precomposition, the corner pin effect will of course stretch it all and it looks pretty bad especially when I write long titles.

I managed to do the scripting again on a shape layer, directly in my main composition. I'm using a rectangle shape.

Here is a screenshot

0_creativecow3.jpg


It works but only on 1 line. And that's because unlike the corner pin effect, I can't have the coordinates of my shape layer points and lock the top points while the bottom points could still move vertically.

I do not wish to take any more of your time but do you think there is a solution for this ?

//Text layer/sourceText

if (time &lt; -1) "E" else
if (time &lt; 0) "É" else value

//Shape layer/Content/Rectangle 1/Rectangle Path/Size

L = thisComp.layer(1);
r1 = L.sourceRectAtTime(-1,false);
r2 = L.sourceRectAtTime(time,false);


[r2.width,r1.height]

//Shape layer/Content/Rectangle 1/Rectangle Path/Position

content("Rectangle 1").content("Tracé rectangulaire 1").size/2;


Return to posts index

Dan Ebberts
Re: How to use "sourceRectAtTime" expression with accents
on Sep 4, 2015 at 4:01:26 pm

Based on what you're trying to do, rather than craft a convoluted expression, I think I'd recommend doing it with a script to size and position your background that you would run after you populate your comps. There's a learning curve, but I think it would give you a more flexible and robust solution.

Dan



Return to posts index

Steve Miller
Re: How to use "sourceRectAtTime" expression with accents
on Mar 19, 2016 at 12:18:04 am

Sebastian,

I've been trying to do the same as you and with help from several sources I finally found a set of expressions that do exactly what I want for centered text, left and right justified text, and with multiple lines:

Try it out!

*steve

{Shape Layer that follows the size of the text input}
ON SHAPE LAYER THAT’S Parented to the text layer:

Rectangle path size expression:

s=thisComp.layer("Text");
paddingx=35;
paddingy=25;
x=s.sourceRectAtTime(time-s.inPoint,true).width;
y=s.sourceRectAtTime(time-s.inPoint,true).height;
[x+paddingx,y+paddingy]

Rectangle Path position expression:

s=thisComp.layer("Text");
rect = thisComp.layer("Try to the me asdasdasd").sourceRectAtTime(time-s.inPoint,true);
[rect.left + 0.5*rect.width, rect.top+0.5*rect.height];


Return to posts index


Steve Miller
Re: How to use "sourceRectAtTime" expression with accents
on Mar 19, 2016 at 12:20:41 am

Oops, this part: "Try to the me asdasdasd" should be "Text" or whatever else your text layer is called.


Return to posts index

Adam Goddard
Re: How to use "sourceRectAtTime" expression with accents
on Apr 7, 2016 at 10:10:55 am

Hi I am trying to get this to work but the text seems to be sitting half out side the bottom of the shape layer, please see this image <a href="https://images.creativecow.net/159926/test.png"><img src="https://i1.creativecow.net/u/159926/test.png" border="0" /></a>


Return to posts index

Adam Goddard
Re: How to use "sourceRectAtTime" expression with accents
on Apr 7, 2016 at 10:15:32 am

Sorry the image didn't work before:
https://images.creativecow.net/159926/test.png


Return to posts index


Steve Miller
Re: How to use "sourceRectAtTime" expression with accents
on Apr 11, 2016 at 5:18:23 pm

Adam,

Remove the parenting from the text, then align both the text and the box in the exact center of the comp then reparent the box to the text.
It should work then...

*steve


Return to posts index

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