Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Expression: X&Y coordinates

  • Expression: X&Y coordinates

    Posted by Erin Patrick on November 8, 2006 at 9:29 pm

    I want to have a text layer that shows the current X&Y coordinates of another layer as it moves across the screen. So, I made a new text layer, added an expression to the source text property, and pickwhipped the position value of the target layer. It worked fine, but my question is, can I get both the X&Y coordinate at the same time, or do I have to do that on two seperate layers of text? Also, how can I limit the number of decimal placesin the text layers to two or three, because now it’s showing about 13 decimal places.
    Thanks in advance for the help!

    Dan Ebberts replied 12 years, 3 months ago 3 Members · 6 Replies
  • 6 Replies
  • Dan Ebberts

    November 8, 2006 at 9:55 pm

    Something like this:

    p = thisComp.layer(“myLayer”).position;
    “” + Math.round(p[0]*100)/100 + ” ” + Math.round(p[1]*100)/100

    Dan

  • Erin Patrick

    November 8, 2006 at 9:59 pm

    WOW! That was exactly what I needed! One day, I’ll get the hang of expressions, hopefully.
    Thanks again.

  • Ian Smith

    April 28, 2014 at 9:27 pm

    This code was very helpful and nearly exactly what I am looking to do as well. I have one slight modification, if anyone may be able to help me.

    I am tracking the coordinates of both the x and y value as if it’s from the 0,0 point. I want to be able to track the change in position easier, so I am ‘zero-ing’ it out.

    The way I have it configured is by using two Nulls.

    Null 1 position is an exact copy of the position.

    Null 1 – ZERO is a duplicate of Null 1, with all keyframes highlighted moved to the 0,0 location. Now I am able to see 0,0 change and see exactly how much. Can I use the code you provided to display this data?

    Thanks so much!

    Ian

    thisComp.layer("5 - TIM").transform.position[0]
    p = thisComp.layer("5 - TIM").position;
    "" + Math.round(p[0]*100)/100 + " " + Math.round(p[1]*100)/100

    Ian Smith

  • Dan Ebberts

    April 28, 2014 at 10:06 pm

    I what you want to do is track how much a layer (“target”) has moved since some arbitrary time (I’m using 0 in this example). I think I’d do it like this:

    p = thisComp.layer(“target”).transform.position;
    d = p – p.valueAtTime(0);
    “x = ” + d[0].toFixed(2) + “, y = ” + d[1].toFixed(2)

    Dan

  • Ian Smith

    April 29, 2014 at 2:24 pm

    Dan,

    This was extremely helpful and exactly what I was looking to display. The only adjustment I made was removing the “x =” and “y =”. Your code works perfectly.

    Would you mind explaining this code a little for me? Usually I am able to understand what is happening in a code, though I’m far less capable of writing my own. I’m very curious how this is working.

    Thanks again!

    Ian Smith

  • Dan Ebberts

    April 29, 2014 at 7:01 pm

    The expression subtracts the target layer’s position at time 0 from it’s current position to calculate how far it has moved. It then converts each component of that distance (x & y) to text using toFixed(2) to limit each number to two decimal places.

    Dan

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