Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Moving existing keyframes with a .jsx-file

  • Moving existing keyframes with a .jsx-file

    Posted by Martin Bollerup on November 22, 2012 at 3:48 pm

    Hello fellow coders,

    Here’s an example:

    I’ve got a layer with two keyframes: in the beginning there’s one with opacity 0 then after 1 sec there’s one with opacity 100 with some custom easing. I would like to move the both keyframes so that they start 3 seconds.

    I can select the keyframes with the code below, but how do I move it? I could add another keyframe with the same values but then any easing done by the designers would have to be copied as well…

    best regards,
    Martin

    {
    function findComp(compName)
    {
    var proj = app.project;
    for( var i = 1 ; i <= proj.numItems; i++) {
    var item = proj.item(i);
    switch (item.typeName) {
    case 'Composition':
    if (item.name == compName) {
    return item;
    }
    break;
    }
    }
    }
    if( ! app.project ) {
    alert("no project");
    } else {
    // Find the mainComp
    mainComp = new Object(findComp("MoveKeyframes"));
    // Find layer
    var layer = mainComp.layer("Layer");
    // Find property
    var opacityProperty = layer.property("Opacity");
    // Select keys
    opacityProperty.setSelectedAtKey(1, true );
    opacityProperty.setSelectedAtKey(2, true );
    var selectedKeys = opacityProperty.selectedKeys;

    // Move selected keys
    // ??????????
    }
    }

    Martin Bollerup replied 13 years, 8 months ago 3 Members · 4 Replies
  • 4 Replies
  • Dan Ebberts

    November 22, 2012 at 4:32 pm

    Unfortunately, as far as I know, you can’t move a keyframe with scripting. You have to create a new one, copy each of the attributes (including easing), then delete the original keyframe.

    Dan

  • Martin Bollerup

    November 22, 2012 at 9:46 pm

    Hmm thought so 🙂

    I tried to fool around with the PropertyGroup object but couldn’t find a way to get anything but errors. Isn’t there a way to copy the easing between to keyframes (all handles on the curve etc.) and add them to another two?

    Thanks,
    Martin

  • Xavier Gomez

    November 24, 2012 at 11:24 am

    There already exists a script that allows to move nearly everything (including keyframes) on a layer’s timeline:

    rd_scooter: link (by Jeff Almasol).

    If what you want is to write your own script, then you can look there to see how it works.

    Xavier

  • Martin Bollerup

    November 26, 2012 at 10:21 am

    Thank you so much Xavier – that just made my monday start like a charm!!!

    Have a great day,
    Martin

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