ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Position of a solid to middle of text

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Adam Greenberg
Position of a solid to middle of text
on Mar 29, 2018 at 3:06:27 pm

HI, I had a hard time titling this post.
I have a text layer in a precomp, ( justified to the left )

and in the main composition I have a solid where the beginning of this solid ( the left side ), needs to be positioned in the middle of the text layer.

So if this text layer is 20 characters long, then the beginning of the solid will be at 10 characters,
and if the solid is 12 characters long, the solid would begin at 6 characters.

I have the following expression that gets as close to possible to what I want, but I got there through trial and error. The math doesn't make sense at all. I don't see why I should divide by 1.7
If some one could suggest a fix and an explanation then that would be great.

so in the position of the solid, my expression is;

gap = 10;
L = comp("text precomp").layer("text layer");
rect = L.sourceRectAtTime(time,false);
x = L.toComp([rect.left+rect.width,0])[0];
[x/1.7+gap+width/2,value[1]]


Return to posts index

Jamie Bradshaw
Re: Position of a solid to middle of text
on Mar 29, 2018 at 3:54:44 pm

Is your font monospaced? If not then you should be careful that the 10th character in a string of 20 characters might not be the middle. Hence why you might be having to fudge things to get the result you were expecting.

Do you want the solid to be in the middle of the text width of your pre comp? Or do you want it to appear on the middle (or between the two middle) characters?

JimJam•Graphics
http://www.jimjamgraphics.com/


Return to posts index

Adam Greenberg
Re: Position of a solid to middle of text
on Mar 29, 2018 at 5:18:49 pm
Last Edited By Adam Greenberg on Mar 29, 2018 at 5:58:17 pm

It appears to be monospaced,
but yes, I want the left edge of that solid to be centered on the text width so that if the amount of characters are odd, then the solid would technically be in the middle of the middle character.

But in all honesty, it is not a deal breaker if its not 100% exact. This solid will be a mask, and the text precomp ( and mask ) will be there twice, animated towards each other so that the text seems to collapse in on itself in the middle while disappearing. So the fact that the center is not mathematically exact will not be noticed by anyone.

But before anyone suggests another way to accomplish this, it should me noted that this is only part of a project with other things going on that i have not mentioned. It was not my project but I`ve been assigned to re-work it into a template. So actually solving this expression I would think could prove useful in other projects in the future.

*note - perhaps there is something I cant figure due to the fact that the text is not justified to the left of the comp, it is more like 400 pixels from the left, but still left justified in the paragraph properties ( meaning the first character is always in the same place )


Return to posts index


Adam Greenberg
Re: Position of a solid to middle of text
on Mar 29, 2018 at 6:02:57 pm

I think that must be it, if the text is 400 pixels from the left of the comp within the precomp, then the expression should be;

gap = 200;
L = comp("text precomp").layer("text layer");
rect = L.sourceRectAtTime(time,false);
x = L.toComp([rect.left+rect.width,0])[0];
[x/2+gap+width/2,value[1]]


Return to posts index

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