• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
1

Using CSV times to perform eases

Community Beginner ,
Mar 23, 2024 Mar 23, 2024

Copy link to clipboard

Copied

Hi! I've been trying to work out how to create a racing leaderboard in after effects that's driven by a CSV (an image of this is shown below).

 

The sheet below has the following columns:

P1: a random racer's position in the order
P2: another random racer (we'll ignore them for the time being)
SecInt: conversion of minutes, seconds, and milliseconds to decimal seconds

 

The racer positions are meant to be displayed using a text box, and I want it to ease every time there's an overtake (as indicated by the times on the timer). I wrote a bunch of code that was borrowed from one of my previous projects, but I can't seem to make it work.

 

Here's the code I have right now inside the source text of P1's position:

OT = footage("Placements.csv");
genData = footage("General Data.csv");
var numbering = ?; // This must be manually set!
var rowNum = 1;
var rowCount = genData.dataValue([1, 8]);
var output;

function easeTo (A, B, C, D) {
var output = ease(time, A, B, C, D);
return Math.round(output);
}

while (rowNum < rowCount)
{
//Step 1: Setting the Variables
startTime = OT.dataValue([4, rowNum]);
endTime = OT.dataValue([4, rowNum]) + 1/5;
prevPos = OT.dataValue([4 + numbering, rowNum - 1]);
newPos = OT.dataValue([4 + numbering, rowNum]);
//Step 2: Creating the Ease
while (time < endTime)
{
output = easeTo (startTime, endTime, prevPos, newPos);
}
//Step 3: Increment + Return to Start
rowNum++;
}
[output]


Note: I have a separate area (in `generalData`) that allows me to enter the number of rows in the CSV. I don't need to have it run infinitely.

TOPICS
Expressions

Views

306

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Mar 24, 2024 Mar 24, 2024

It's a little tricky, but this might be helpful. First, I think you should drag the csv into your timeline so the expression can easily reference the number of rows from the data itself. Then try this as a source text expression:

 

OT = footage("Placements.csv");
easeTime = .2;
myCol = 5;
numRows = thisComp.layer("Placements.csv")("Data")("Number of Rows");

pos = OT.dataValue([myCol,0]);
for (i = 0; i < numRows; i++){
  if(time < OT.dataValue([4,i])) break;
}
i--;
if (i > 0){
  t1 = OT.dataValu
...

Votes

Translate

Translate
Community Expert ,
Mar 23, 2024 Mar 23, 2024

Copy link to clipboard

Copied

It's not clear from your code (to me at least) exactly how your animation is supposed to work. A detailed description would very helpful.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 24, 2024 Mar 24, 2024

Copy link to clipboard

Copied

Hi Dan,

My apologies for the confusion. Let me try to do a better explanation.

 

Shown below is a single row on the timing tower. Notice the square with the number 1 inside it. This is the racer's current position (henceforth referred to as curPos) in the race.

 

Now, if you take a look at the Placements.csv that I linked, the racer moves up to 1st place at 0:07:32 (secInt is just there to convert the timer to a single value that can be used for expressions). What I want to do is the following:

- Every time the timer reaches a point where a new overtake is made, do the following:
- Ease curPos from its previous value to its new value. For instance, at 0:07.32, it should ease from 3 to 1.
- Do this for every single row in the CSV.

 

Please let me know if this is still unclear.

Thanks,
Josh994

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 24, 2024 Mar 24, 2024

Copy link to clipboard

Copied

I forgot to attach this...

Jsh994_0-1711299473582.png

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 24, 2024 Mar 24, 2024

Copy link to clipboard

Copied

So how are the multiple racers displayed? Are they each in their own column, or are they all in the same column? If they're all in the same column, at time 7.32, for example, where P3 and P5 are both in 5th place, are they on top of each other? Maybe post what the whole display should look like at a couple of different times.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 24, 2024 Mar 24, 2024

Copy link to clipboard

Copied

OK, sorry. Now I think I understand that the displays aren't moving, just the place numbers are changing. So when you say "ease from 3 to 1", what does that look like, and how long does it take?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 24, 2024 Mar 24, 2024

Copy link to clipboard

Copied

Hello Dan, thank you for your reply.

1. The racers are all moving (I have them in separate compositions); I just need to establish how to move one of them, and then I'll have a foothold as to how it should work.
2. I'm only working on easing the placements right now, as the vertical position on screen will follow afterward.
3. Each ease takes 0.2 seconds, hence the + 1/5 at the end of:
> endTime = OT.dataValue([4, rowNum]) + 1/5;
4. P3 and P5 being at the same position is a mistake. Sorry about that!
5. I have posted what the row should look like before and after.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 24, 2024 Mar 24, 2024

Copy link to clipboard

Copied

It's a little tricky, but this might be helpful. First, I think you should drag the csv into your timeline so the expression can easily reference the number of rows from the data itself. Then try this as a source text expression:

 

OT = footage("Placements.csv");
easeTime = .2;
myCol = 5;
numRows = thisComp.layer("Placements.csv")("Data")("Number of Rows");

pos = OT.dataValue([myCol,0]);
for (i = 0; i < numRows; i++){
  if(time < OT.dataValue([4,i])) break;
}
i--;
if (i > 0){
  t1 = OT.dataValue([4,i]);
  t2 = t1 + easeTime;
  v1 = OT.dataValue([myCol,i-1]);
  v2 = OT.dataValue([myCol,i]);
  pos = ease(time,t1,t2,v1,v2);
}
pos

You may want to round pos, as you did in your expression, but without the rounding you'll see the easing.

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 24, 2024 Mar 24, 2024

Copy link to clipboard

Copied

LATEST

Actually, this is exactly what I needed. I'll configure the y position somewhere else, but this is the foothold that can get me started. Thank you very much!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines