Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Control time remap with spreadsheet

  • Control time remap with spreadsheet

    Posted by Bryan Woods on March 13, 2014 at 2:17 am

    Working with both animation sequences and batches of hand drawn frames at varying frame rates and I would like to know if there is a way to control a time remapped image sequence from a simple spreadsheet.

    I have to break out the timing of key poses and sometimes poses need to be held for many frames to make up the timing where inbetweens will go later. If I have a simple spreadsheet that documents how long each key pose needs to be held for, can I use this to put in hold key frames in a time remap of an image sequence?

    Thanks!

    Bryan Woods replied 12 years, 4 months ago 2 Members · 28 Replies
  • 28 Replies
  • Bryan Woods

    March 14, 2014 at 12:53 am

    No suggestions yet? Bummer. 🙁

    If anyone is not sure what I’m trying to do here, please let me know and I can elaborate. I know this will require a script, not just an expression, but how to start the script and take values from a spreadsheet i’m not sure about and looking for suggestions.

  • Dan Ebberts

    March 14, 2014 at 3:57 am

    You’re correct in that you need to do this with a script. You can export your spreadsheet as a tab-delimited text file, which you can then read (using the file I/O commands). What you do with the data depends on the structure of your project and your data file, but as far as scripting goes, it’s a fairly straightforward application. Maybe you have more specific questions.

    Dan

  • Bryan Woods

    March 17, 2014 at 9:49 pm

    Ok, lets think about this a different way. What I really need to accomplish is setting a hold keyframe for every frame of an animation’s key poses. We know what the frame rate is and how long each frame needs to be held out for, so really, I just need to set up a system to take an input of How many key poses are there, and how long each hold keyframe needs to be for.

    So here’s the process:
    Ask user how many frames in the image sequence there are. Save that value and call it “f”.
    Ask the user how long each frame should last (in frames). Save this as “fLength”.

    Now, from the current time indicator in your comp, on the selected layer, go through each frame and set a hold keyframe for the set amount of time. Lets say frame 1 of the comp has a hold keyframe on time remap set to “1”. Advance 4 frames, then set another hold keyframe on time remap, this time as “2”. Advance 4 more frames, set another hold keyframe, this one as “3”, etc. Make sense?

    So what I know so far is I need a loop to advance through the given number of frames, and to advance each set hold keyframe by one, but I don’t know how to do that. I know if you do something like lets say “i++’, this will advance the loop, but how do I say when I set a hold keyframe, to advance the value of that hold keyframe by one?

    Here’s some rough code that I have at the moment (and some sudo code):

    {

    //Set Undo Group
    app.beginUndoGroup("xsheet_remap");

    //Define project and active items
    var proj = app.project;
    var theComp = proj.activeItem;
    var selectedLayers = theComp.selectedLayers;

    activeLayer = comp.selectedLayers[0];
    curTime = comp.time;

    var numFrames = parseFloat(prompt("Number of frames"));
    var holdLength = parseFloat(prompt("Hold each frame this # of frames"));

    for (var f=1; f<numFrames; f++ ){
    activeLayer.timeRemap.addKeyAtTime(f);
    advance "holdLength"; //sudo code
    }

    app.endUndoGroup("xsheet_remap");
    }

  • Bryan Woods

    March 17, 2014 at 11:34 pm

    Here’s the closest I’ve come so far however I can’t figure out how to convert keyframes to hold keyframes, and its not skipping the set number of frames I want. :

    {

    //Set Undo Group
    app.beginUndoGroup("xsheet_remap");

    //Define project and active items
    var activeItem = app.project.activeItem;
    var selectedLayer = activeItem.selectedLayers[0];
    var curTime = activeItem.time;

    //testing variables
    var numFrames = 5;
    var holdLength = .6;

    //Meat and Potatoes
    for (var f=1; f&lt;=numFrames; f++){
    if (selectedLayer.timeRemapEnabled == false){
    selectedLayer.timeRemapEnabled = true;
    }else{
    selectedLayer.timeRemap.addKey(f);
    selectedLayer.timeRemap.setInterpolationTypeAtKey(selectedLayer, KeyframeInterpolationType.LINEAR, KeyframeInterpolationType.HOLD);
    curTime+holdLength;
    }
    }

    app.endUndoGroup("xsheet_remap");
    }

  • Dan Ebberts

    March 17, 2014 at 11:52 pm

    A couple of things–your times need to be in seconds, not frames, so you should multiply the frame number by the comp’s frameDuration to convert to seconds. This would be for both the timing and value of your keyframes.

    The first parameter for setInterpolationTypeAtKey() should be the key index, which you can get by saving the reslut of addKey() into a variable:

    var myKeyIdx = selectedLayer.timeRemap.addKey(f*activeItem.frameDuration);

    Dan

  • Bryan Woods

    March 18, 2014 at 12:20 am

    Thanks Dan. Thats solving part of my issues. I’m now seeing the correct number of keyframes indicated, but the first keyframe created is always a regular keyframe (diamond), while the others are linear Hold frames (square with a notch cut into its left side). Also, the distance in frames from the first keyframe to the second is two frames, but every keyframe after the second is one frame apart. So the input for duration between the hold keyframes isn’t being set properly.

  • Dan Ebberts

    March 18, 2014 at 12:38 am

    I think your frame number probably needs to start at zero and the time would be the frame number times the time between keyframes times the frame duration.

    Dan

  • Bryan Woods

    March 18, 2014 at 1:01 am

    Ok, we’re getting closer, but I still can’t get each hold keyframe to increase by one frame. the first keyframe set should be 1, the second 2, the third 3, etc. Right now, I”m getting this strange occurrance where there is a linear keyframe at the start and end of the layer, and in between I’m getting the proper number of keyframes.

    Also notice where the playhead is and its reading “5”, but it should read “3”.

    Here’s my code so far:

    {

    //Set Undo Group
    app.beginUndoGroup("xsheet_remap");

    //Define project and active items
    var activeItem = app.project.activeItem;
    var selectedLayer = activeItem.selectedLayers[0];
    var curTime = activeItem.time;

    //testing variables
    var numFrames = 5;
    var holdLength = 5;

    //Meat and Potatoes
    for (var f=0; f&lt;=numFrames; f++){
    if (selectedLayer.timeRemapEnabled == false){
    selectedLayer.timeRemapEnabled = true;
    }else{
    var myKeyIdx = selectedLayer.timeRemap.addKey(f*holdLength*activeItem.frameDuration);
    selectedLayer.timeRemap.setInterpolationTypeAtKey(myKeyIdx, KeyframeInterpolationType.LINEAR, KeyframeInterpolationType.HOLD);
    }
    }

    app.endUndoGroup();
    }

  • Dan Ebberts

    March 18, 2014 at 2:22 am

    Try it this way:


    {

    //Set Undo Group
    app.beginUndoGroup("xsheet_remap");

    //Define project and active items
    var activeItem = app.project.activeItem;
    var selectedLayer = activeItem.selectedLayers[0];
    var curTime = activeItem.time;

    //testing variables
    var numFrames = 5;
    var holdLength = 5;

    //Meat and Potatoes
    if (! selectedLayer.timeRemapEnabled) selectedLayer.timeRemapEnabled = true;

    for (var f=0; f < numFrames; f++){
    var myKeyIdx = selectedLayer.timeRemap.addKey(f*holdLength*activeItem.frameDuration);
    selectedLayer.timeRemap.setInterpolationTypeAtKey(myKeyIdx, KeyframeInterpolationType.LINEAR, KeyframeInterpolationType.HOLD);

    }

    app.endUndoGroup();
    }

    Dan

  • Bryan Woods

    March 18, 2014 at 4:08 am

    Hi Dan, this does not seem to change my result with the previous code I applied. Each hold keyframe, while spaced properly, does not reflect the proper value in the time remap effect. Each hold keyframe displays “0”. I need each keyframe to represent one frame of the image sequence. Hold keyframe 1 should read “1”, as in 1 frame on the time remap effect. Hold keyframe 2 should read “2” in time remap, etc. up to the numFrames variable originally set (which will later turn into a user defined variable with a prompt to put in a custom number). I’m not certain, but your latest code just looks like you put in a shorter version of identifying whether time remap is hidden or not and to enable it.

    There’s also the issue that I have one keyframe at the very end of my layer. Its just a lone linear keyframe, and I’m not sure where that’s coming from.

Page 1 of 3

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