ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Link external JSON file to Slider Control effect and animate

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Aaron Riggs
Link external JSON file to Slider Control effect and animate
on Apr 22, 2018 at 8:01:49 pm

Hello,
Needing help from those who know AE Expressions far more than I.
I’m wondering if it’s possible, and how, to use data from an external JSON file to define the value of the Slider Control effect on a layer, and have the slider move to defined values at specific points in time based on data also from the JSON file.

So, for example. I want to define the following in my JSON file:

{
"ID": 1,
“slider”: 80,
"duration": 3
},
{
"ID": 2,
“slider”: 40,
"duration": 6
},
{
"ID": 3,
“slider”: 60,
"duration": 2
},



Then, I’d like AE to use that data to set the Slider Control effect on a layer to be at 80 for a duration of three minutes, and then to animate linearly to 40 at the end of the first three minutes and stay at 40 for six minutes. And then at the end of 6 minutes, I want the slider to animate to 60 and stay at 60 for two minutes… etc.
When the slider animates, it should animate linearly over the coarse of 3 seconds.

Does anyone know if this is possible? My intent is to easily update the JSON file with new values and quickly render.


Return to posts index

Dan Ebberts
Re: Link external JSON file to Slider Control effect and animate
on Apr 23, 2018 at 12:49:07 am

If you put your data in an array, like this:


[
{
"ID": 1,
"slider": 80,
"duration": 3
},
{
"ID": 2,
"slider": 40,
"duration": 6
},
{
"ID": 3,
"slider": 60,
"duration": 2
}
]


then save it as a .jsx file ("example.jsx" in this case), import it into AE, then something like this should work:


data = footage("example.jsx").sourceData;
rampTime = 3;
done = false;
i = t = tPrev = 0;
while (t <= time){
tPrev = t;
t += rampTime + parseFloat(data[i].duration)*60;
i++;
if (i >= data.length){
done = true;
break;
}
}
if (done){
parseFloat(data[data.length-1].slider);
}else{
if ((time - tPrev) < parseFloat(data[i-1].duration)*60){
parseFloat(data[i-1].slider);
}else{
v1 = parseFloat(data[i-1].slider);
v2 = parseFloat(data[i].slider);
t1 = parseFloat(data[i-1].duration)*60;
t2 = t1 + rampTime;
linear(time-tPrev,t1,t2,v1,v2);
}
}


This assumes you have the latest version of AE. I didn't test it thoroughly, so it may not be quite right (or as efficient as it could be), but it should give you the idea.

Dan



Return to posts index

Aaron Riggs
Re: Link external JSON file to Slider Control effect and animate
on Apr 23, 2018 at 6:54:18 pm

Go it to work! Very impressive. Thank you very much!


Return to posts index


Aaron Riggs
Re: Link external JSON file to Slider Control effect and animate
on Apr 23, 2018 at 8:08:39 pm

I spoke too soon! So there's an issue involving ' rampTime = '. If I set it to '0', then the slider value changes at the right moment in time, as it corresponds with the defined duration in the .jsx file.
But if I set the number to any other value, say '1', then the equation adds that amount (in seconds) to the next duration, and it compounds after that.
So after 20 rounds of data, the last linear slider movement is 19 seconds off from it's intended moment to slide.
For example, using the data array above, the first slider movement happens at 3:00:00. The next movement is suppose to occur at 9:00:00 (duration 3 + 6), but it's occurring one second late at 9:01:00 because the rampTime = 1.

Any ideas on a possible solution? Seems like a subtraction of the rampTime needs to occur, but I'm not sure where or how.

Thank you!


Return to posts index

Dan Ebberts
Re: Link external JSON file to Slider Control effect and animate
on Apr 23, 2018 at 8:22:47 pm

I guess that would be like this:


data = footage("example.jsx").sourceData;
rampTime = 3;
done = false;
i = t = tPrev = 0;
while (t <= time){
tPrev = t;
t += parseFloat(data[i].duration)*60;
i++;
if (i >= data.length){
done = true;
break;
}
}
if (done){
parseFloat(data[data.length-1].slider);
}else{
if ((time - tPrev) < (parseFloat(data[i-1].duration-rampTime))*60){
parseFloat(data[i-1].slider);
}else{
v1 = parseFloat(data[i-1].slider);
v2 = parseFloat(data[i].slider);
t2 = parseFloat(data[i-1].duration)*60;
t1 = t2 - rampTime;
linear(time-tPrev,t1,t2,v1,v2);
}
}



Dan



Return to posts index

Aaron Riggs
Re: Link external JSON file to Slider Control effect and animate
on Apr 23, 2018 at 8:41:48 pm

That did it! Thanks, Dan, really appreciate it!


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 CreativeCOW.net All Rights Reserved
[TOP]