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

  • Dan Ebberts

    March 18, 2014 at 4:20 am

    Ah, OK, sorry–I didn’t really test it. This should work better:

    {

    {

    //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 t = f*holdLength*activeItem.frameDuration;
    selectedLayer.timeRemap.setValueAtTime(t,t);
    selectedLayer.timeRemap.setInterpolationTypeAtKey(f+1, KeyframeInterpolationType.LINEAR, KeyframeInterpolationType.HOLD);

    }
    selectedLayer.timeRemap.removeKey(numFrames +1);
    app.endUndoGroup();
    }
    }

    Dan

  • Bryan Woods

    March 18, 2014 at 5:27 am

    Still not there, but we’re really close. The issue still is that each hold keyframe is taking on the numeric frame value of its point in time. So lets say the second hold keyframe in the comp has a value of “0005”, because it is at the 5th frame of the comp. But what it should be reading is “0002”. Because its the second keyframe set in the comp.

    Would it be easier to run a loop that counts how many keyframes have been previously put in, and then add one to the next keyframe’s value? Kind of like using index+1 or something similar? Thats the final piece of this. Each keyframe needs to represent its own index within all the other keyframes of the time remap effect. I’m thinking multiplying the numFrames variable by the selected layer’s frame duration might not be the right answer. Or, “setValueAtTime” is overriding our initial result with the current frame number.

  • Dan Ebberts

    March 18, 2014 at 7:52 am

    Maybe you just need to set the value like this:

    selectedLayer.timeRemap.setValueAtTime(t,f+1);

  • Bryan Woods

    March 18, 2014 at 3:14 pm

    This causes the first hold keyframe at frame 1 to be “30”, the second keyframe on frame 10 to be “60”, etc.

    Again, very close, but we’re still not getting what I’m looking for. Is there a way to calculate how many keyframes are currently on the time remap effect and then add 1 to the next keyframe placed? So if there’s already 4 hold keyframes, the next hold keyframe set will be the 5th, reading “0005” on the time remap effect.

    This is more accurate I feel because eventually, I would like to be able to run this script from the current point my timeline indicator is, not necessarily from the beginning of a comp or layer. So if I ran this script and my timeline playhead was in the middle, this whole script would start from the middle. But it needs to be aware of keyframes that might be present before the script started laying down new ones.

  • Bryan Woods

    March 21, 2014 at 10:50 pm

    Hey Dan, I went back and messed with it a little and finally got the result I was looking for! Below is the code I’m using. I had to change the second input to f*activeItem.frameduration to get the incremental frame number value.

    Now, the big question to get this working as I need it to, how can I have this script run from where the playhead is? If I run this script once from the beginning, then run it again, from the middle of the comp, the script should add keyframes from the playhead, starting from the number of the last keyframe +1. So if I ran the script, and the last keyframe is 5, and I run the script again somewhere later in the timeline, that first keyframe made by running the script a second time should read “6”, and continue from there. Does that make sense?

    Thank you for your help!

    {

    {

    //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 = 10;
    var holdLength = 5;

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

    for (var f=1; f &lt;= numFrames; f++){
    var t = f*holdLength*activeItem.frameDuration;
    selectedLayer.timeRemap.setValueAtTime(t,f*activeItem.frameDuration);
    selectedLayer.timeRemap.setInterpolationTypeAtKey(f+1, KeyframeInterpolationType.LINEAR, KeyframeInterpolationType.HOLD);

    }

    selectedLayer.timeRemap.removeKey(numFrames+1);
    app.endUndoGroup();

    }

    }

  • Dan Ebberts

    March 21, 2014 at 11:32 pm

    I think you just need a variable for the startFrameCount that is zero if there are no keyframes or numKeys if there are, and you would include that number in your value calculation.

    I can see you have a curTime variable already–I think you would just need to add that into the calculation for t.

    Dan

  • Bryan Woods

    March 22, 2014 at 12:13 am

    I can’t seem to find any documentation on how to control the current time in script. I’m assuming it may have something to do with nearestKey() + time or something, but how do I say to start where the playhead is currently? I’m not sure how to capture that result and set it as a variable. But I know it will be have to be a combination of checking for previous keyframes, and if so, add the total number of keys and add 1 to the value of the next key placed (and then add 1 from there on).

    Also, would I need to embed a loop checking for keyframes inside the main loop adding initial keyframes?

  • Dan Ebberts

    March 22, 2014 at 12:21 am

    You already have a variable (curTime) with the playhead time. You could set the comp time to 2 seconds (for example) like this:

    activeItem.time = 2;

    I don’t understand your second question, but I don’t think you’ll need a loop. You can get the number of keyframes, and get the time of any keyframe directly. So I would get the time of the last keyframe and make sure the playhead is beyond that (assuming it’s important to add new keyframes after the last previous keyframe).

    Dan

  • Bryan Woods

    March 22, 2014 at 12:32 am

    I guess what I’m not understanding is how to utilize my variable curTime. curTime was a variable left over from trying to test timing, but I couldn’t figure out how to get it to work for me. How do I use my var curTime to start my current loop at the current playhead time? just putting “curTime;” at the beginning of the loop doesn’t do anything. The script runs, but starts from the start of the comp, not where my playhead is.

  • Dan Ebberts

    March 22, 2014 at 12:40 am

    You need to include it in the calculation of variable t.

Page 2 of 3

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