Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Position of a solid to middle of text

  • Position of a solid to middle of text

    Posted by Adam Greenberg on March 29, 2018 at 3:06 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]]

    Adam Greenberg replied 5 years, 11 months ago 2 Members · 3 Replies
  • 3 Replies
  • Jamie Bradshaw

    March 29, 2018 at 3:54 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
    https://www.jimjamgraphics.com/

  • Adam Greenberg

    March 29, 2018 at 5:18 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 )

  • Adam Greenberg

    March 29, 2018 at 6:02 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]]

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy