Skip to main content
July 22, 2012
Answered

Importing keyframes from text file

  • July 22, 2012
  • 1 reply
  • 8647 views

Is that possible? I have keyframe data that is in the format of After Effects keyframes, like when you do strg+c on a keyframe animation in After Effects and paste that into a text editor.

Now I want to reverse that process with a script that reads a text file with said data and applies it onto a layer. I looked into the CS3 scripting guide but couldn't find anything like that. Google wasn't much help either.

This topic has been closed for replies.
Correct answer Dan Ebberts

A lot of what you'll need is in the File System Access section of Adobe's JavaScript Tools Guide (in AE: File>Scripts>Open Script Editor; in ExtendScript editor: Help > JavaScript Tools Guide).

Like this to open the keyframe file:

var myFile = File.openDialog("Navigate to keyframe file.");

myFile.open("r");

Then use

var myLine = myFile.readln();

to read the file line-by-line.

The parsing itself would be pretty much pure JavaScript string operations, and then create the keyframes.

Not too tough, even for a first scripting project.

>What do you mean exactly with a preset?

You can select a property to highlight all the keyframes and then Animation>Save Animation Preset. Then you can apply the preset to other layers. But it sounds like that might not help in your situation.

Dan

1 reply

Dan Ebberts
Community Expert
Community Expert
July 23, 2012

There's nothing in the scripting language will do that for you directly--I think you'd have to write a simple parser to read the file and create the keyframes. It should be pretty straightforward. I'd set it up to assume that you have the target layer selected. Your script would read the keyframe file to get the property name and the frame rate, then, for each keyframe entry, calculate the time and apply the value using setValueAtTime(). It could get more complicated if the keyframes are for an effect property and you want the apply the effect if it doesn't exist.

That being said, why not just create a preset?

Dan

July 23, 2012

Thanks for your answer!

I actually write the keyframe data out of another program so I have control over how the data is formatted (which should make the parsing easier I guess). Currently I format it so I can manually copy paste it but that is pretty annoying thats why I want to do this script.
I have a keyframe for every frame, so tbh I have no idea how I would do a parser that just goes from line to line (don't know if thats even possible in JS, I just started using it) and collects the correct data for xyz for Position and Rotation. I imagine that being pretty complex than being simple :/

Is there some way to make standard GUI interaction in the script? I actually just have to do what I already do manually in after effects with the sript.

What do you mean exactly with a preset? When I hear preset with After Effects than I think of Workspace presets :s

Dan Ebberts
Community Expert
Community Expert
July 25, 2012

Thats what I feared.
I will have a lot of keyframes (100+) and the amount will differ. How would I do that in this case?

Declaring an array for each frames can't be the solution (I hope). Can I store my values in its its own array directly to the posArray without specifing a name for each array?


Sure. I'd just create empty arrays:

var posArray = [];

var timeArray = [];

then, inside your loop, parse the time (t),  x, and y values and add them to the end of their arrays:

posArray.push([x,y]);

timeArray.push(t);

Dan