Skip to main content
MatteoMasciotti
Participating Frequently
December 17, 2022
Question

values to keyframes from a json

  • December 17, 2022
  • 1 reply
  • 532 views

Hello everyone,

I generally work with json dataset inside after effects and by using linear expressions I am generally able to create animation between two values. This time around though I am facing a new challenge:

I have a slider with a number of keyframes, what I want is for my keyframes to match the value of my json file. so for example, my first keyframe should be exactly the value of the year 2017, my second key should be exactly the value of the year 2018...and so on and so forth. As i said, i could've used alinear expression to map two marker keys with the values coming from a dataset...but this doesn't apply in this context.

How would you tackle this challenge?

 

Thanks for reading and caring.

This topic has been closed for replies.

1 reply

Mylenium
Legend
December 17, 2022

Could be as trivial as a for() loop combing through your columns and then doing a break when it hits the correct value, assuming the values are in the same row on your file. Something along those lines perhaps:

 

mData=thisComp.layer("XYZ").sourceData();

for (i=0;i<mData[0].length;i++)
{
if (mData.dataValue[1][i] == key(i).value)
{
mYear=mData[0].dataValue[i]
break
}
else
{
mYear=1999;
}}

 

I'm making this up on the fly, so no guarantees, but I think you get the idea what is supposed to do. You basically just compare the columns and match the index if you find a value. Depending on what you need to do you may also need to figure out the current keyframe with that key.nearestKey() stuff as illustrated e.g. here:

 

http://www.motionscript.com/design-guide/marker-sync.html

 

Mylenium