Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Expression(s) to center midpoint of 3 separate layers to center of the comp

  • Expression(s) to center midpoint of 3 separate layers to center of the comp

    Posted by Teddy Denton on September 11, 2019 at 1:20 am

    I feel like I’m close here, but I just can’t get over the hump… I’m working on a project where I’m using an imported .jsx file with data fields drawn from a spreadsheet to populate the text layers on my animation. For example, the .jsx file might be something simple like this:

    var data = {
    name: “Jane Smith”,
    phone: “(415) 395-8281”,
    location: “SAN MATEO, CA”,
    headline: “Call or email to schedule\n an appointment”
    };

    I’m then linking the source of the text layer to one of those fields, allowing me update all linked text fields by just importing a new .jsx, etc…

    In one of my animations I have 2 text layers separated by a dot, something like this:

    (555) 555-5555 · SAN MATEO, CA

    The phone number and city need to be separate layers as I’m sourcing them from separate data fields in the .jsx, but I want the entire line of text (including dot) to be centered on its midpoint. (Not on the dot… Right now I’m using a shape layer circle as my dot.) Obviously the midpoint will shift depending on the length of the city (and phone # to small degree), so here was my first stab at it:

    I established the spacing I wanted on either side of the dot with my two text layers. For the phone number I made the text right justified, placed the anchor point on the far right edge of the text layer and spaced it 20px left of the dot. I did the opposite for the city – left justified, anchor point on left edge, positioned 20px to right of dot. Anchor point for the shape layer is at its center, both text layers are parented to the circle.

    Next, I figured to find the midpoint I need to find the total width and divide by 2. To do this I applied this expression to the anchor point:

    L = thisComp.layer(“phone”).anchorPoint[0]; // x value of anchor point of phone #
    R = thisComp.layer(“city_state”).anchorPoint[0]; //x value of anchor point of city
    gap = R – L; // x-distance b/t 2 text layers
    midpoint = (gap + thisComp.layer(“phone”).width + thisComp.layer(“city_state”).width)/2; // (width of 2 text layers + distance b/t them)/2
    diff = midpoint – thisComp.layer(“phone”).width; // midpoint – width of left text layer
    [value[0]-diff,value[1]] // supposed to shift anchor point to midpoint

    It acts basically like it should, but it doesn’t move quite to the midpoint. Am I way off or is there something I’m overlooking? At this point I’m just confusing myself the more I look at it.

    Thanks in advance for the help!

    Teddy Denton replied 6 years, 11 months ago 2 Members · 2 Replies
  • 2 Replies
  • Andrei Popa

    September 11, 2019 at 7:17 am

    I’m not sure why you want them to be different layers. Could you not give the text this value?
    data.phone+ "·"+data.location

    Andrei
    My Envato portfolio.

  • Teddy Denton

    September 11, 2019 at 5:12 pm

    Welp I feel dumb. That’s a much easier solution. Thank you Andrei!

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