Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Forums Adobe After Effects Expressions Move keyframes in timeline using expressions

  • Move keyframes in timeline using expressions

  • Paul Connors

    March 30, 2020 at 7:46 pm

    I’m looking to use a .CSV file that has tracking data for an object over time. The data has the different XY position coordinates and at what time the object was at those coordinates. I want to use all this information to power a dot moving from position to position. I’d like to do it all with expressions so I can update the data and the animation will update. Anyone got any tips / strategies to attack this? I’ve got a good idea on transferring the XY positional data to AE (still open to suggestions on this one if anyone has a favorite method), but I don’t have a strategy for manipulating the times/timing. Any tips would be great. Thank you.

  • Andrei Popa

    March 30, 2020 at 9:44 pm

    I hope you have some knowledge about expressions because this will be a little bit hard to explain.

    I have some values, you will have to modify the expression to satisfty your needs.

    My csv has 2 columns: Times and Positions. First has some numbers, second has some 2 dimension arrays.
    I put my csv inside the timeline and pick-whip from the expression to “positions.csv>Data>Times 0″(layer, property, property) to see how the expression to link the first time would look like. Mine is thisComp.layer(“positions.csv”)(“Data”)(“Outline”)(“TImes”)(“TImes 0”).
    same for Positions, i get thisComp.layer(“positions.csv”)(“Data”)(“Outline”)(“Positions”)(“Positions 0”);. Considering these 2 paths, my expression looks like this:

    myData = thisComp.layer("positions.csv")("Data")("Outline");
    while(myData("Times")("Times "+i).value < time && i < myData("Times").numProperties-1) i++

    initTime = myData("Times")("Times " + (i-1)).value;
    endTime = myData("Times")("Times " + i).value;
    initPosition = eval(myData("Positions")("Positions "+(i-1)).value);
    endPosition = eval(myData("Positions")("Positions "+(i)).value);


    I think that what you need to do is replace what comes after myData with what you have. Or make a 2 column table with the columns named Times and Positions as your csv.

    My Envato portfolio.

  • Christine Tang

    June 22, 2020 at 9:15 pm

    Hi Andrei,

    Do you know how you would get this to work on a path? To keep receiving data from a .csv but also for the animation to stay within the path or keep it within a maximum or minimum so it cannot stray away from the path outline?

    I am trying to animation a train with data from a .csv as accurately.

    Thank you.

  • Andrei Popa

    June 23, 2020 at 12:02 pm

    I need more data to answer you.
    What kind of data you have in your CSV? This expression works on position with the data being coordinates for those positions.

    My Envato portfolio.

  • Christine Tang

    June 23, 2020 at 3:18 pm

    I have data of Time and KMpoint. KM starts from 105769 to 120458 with stops in-between. I was wondering if it was possible to animate this on a path and have my .CSV provide the points in-between.
    I tried using a Trim Path but trim path’s work by percentage so I couldn’t do that.
    I was wondering if there’s a way to create a path and my train image can be attached and travels along the path by my .csv data.

    This is my alternative attempt to accomplish the same thing:
    I tried your other method above, where I had Times, PositionX, and PositionY. I separated my position coordinate and had the expression:

    myData = thisComp.layer(“PositionXPositionY.csv”)(“Data”)(“Outline”);
    while(myData(“Times”)(“Times “+i).value < time && i < myData(“Times”).numProperties-1) i++

    initTime = myData(“Times”)(“Times ” + (i-1)).value;
    endTime = myData(“Times”)(“Times ” + i).value;
    initPosition = eval(myData(“PositionX”)(“PositionX “+(i-1)).value);
    endPosition = eval(myData(“PositionX”)(“PositionX “+(i)).value);


    Problem with this method is my PostionX and PositionY coordinates are extremely large values like, 1,000,000. This expression is for the screen aspect ratio, 1080p for me so it would not work unless I increase my ratio to the same size.

    I was wondering if you had a solution to any of these scenarios? My intention is to have an animation of my train following my .csv position points accurately. I have tried 2 alternatives to make this work but I don’t know which would be better.

    Thank you.

  • Andrei Popa

    June 24, 2020 at 9:04 am

    I am a little confused. You said you have km as stops but you used x position and y position.

    However, if you want a straight line, like a loading bar, and your train to move on that, you can use this on x position.

    sPos is what you want your start value to be. I chose 100 away from the edge of my comp. Same for ePos(just end).
    minValue and maxValue are the minimum and maximum kilometer you provided here. You can change this to whatever you want also. They should be the maximum and minimum value of the column you take your data from.

    var sPos = 100; //start position value.
    var ePos = 1820; //end position value
    var minValue = 105769; //min from table
    var maxValue = 120458; //max from table
    myData = thisComp.layer("PositionXPositionY.csv")("Data")("Outline");
    i = 1;
    while (myData("Times")("Times " + i).value < time && i < myData("Times").numProperties - 1) i++;

    initTime = myData("Times")("Times " + (i - 1)).value;
    endTime = myData("Times")("Times " + i).value;
    initRawPosition = eval(myData("PositionX")("PositionX " + (i - 1)).value);
    endRawPosition = eval(myData("PositionX")("PositionX " + i).value);
    initPosition = linear(initRawPosition,minValue, maxValue,sPos,ePos);
    endPosition = linear(endRawPosition,minValue,maxValue,sPos,ePos);

    linear(time, initTime, endTime, initPosition, endPosition);

    Similar to this technique, you can also turn it into percentage for trim paths. If you take this expression, and modify sPos and ePos to 0 and 100, and put it on a trim paths end property, you will have a line that fills according to the data from your table.

    My Envato portfolio.

  • Andrei Popa

    June 24, 2020 at 9:05 am

    Also, I have not checked this with a csv file but with some values I manually inserted. You may have to change some stuff to correctly take the values from the csv file.

    My Envato portfolio.

  • Christine Tang

    June 26, 2020 at 5:31 pm

    Thank you Andrei, everything worked perfectly! I appreciate you taking your time out to help me out.

Viewing 1 - 8 of 8 posts

Log in to reply.

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