Skip to main content
Known Participant
June 29, 2019
Answered

Convert all keyframes to easy ease or linear

  • June 29, 2019
  • 1 reply
  • 1388 views

Hi there

I m new around and scripting. I write some code that iterates through all items, comps, layers then activates motion blur for each layer, comps.

Where i stuck is reaching all properties of all layers in all comps then every keyframes and change interpolation to easy ease or linear. Here is my script for motion blur :

[code]

//Enables disables motion blur for all layers and activates global motion blur switch for all comps.

//.numItems = extracts total number of items in defined variable = proj;

var proj = app.project;

var itemTotal = proj.numItems;

var curItem, curComp, totalComps, totalLayers, curLayer;

var itemAry = new Array ();

//iterate all items through project

for (var i = 1; i<= itemTotal; i++){

   

curItem = proj.item(i);

//check if current item is a comp

if(curItem instanceof CompItem){

   

    itemAry[itemAry.length] = curItem;

   

    }

   

   

    }

totalComps = itemAry.length;

for (var c = 0; c<totalComps; c++){

   

   

    curComp = itemAry;

    totalLayers = curComp.numLayers;

   

//enable global motion blur for all comps   

   

    curComp.motionBlur = true;

   

//loop layers + iterate all layers and enable motion blur for iterated layers

   

    for (var l=1; l<=totalLayers; l++){

       

        curLayer = curComp.layer (l);

       

       

//enable motion blur for all iterated current layers

       

        curLayer.motionBlur=true;

       

        }

   

   

    }

[/code]

I dont know if i can continue from here on or need to start from scratch. Any help or tip will be appreciated.

This topic has been closed for replies.
Correct answer Justin Taylor-Hyper Brew

Sorry for troubling but when i run code like below it returns an error and after stopping debug it only applies ease to keys of first property.

Update : It works with position rotation tranparency. But when i add keys to scale, it returns this error.

var keyedProps = getPropsWithKeys(app.project.activeItem.layers[1]);

for (var i = 0; i < keyedProps.length; i++) {

    var curProp = keyedProps;

     var numKeys = curProp.numKeys;

     for(var j = 0; j < numKeys; j++){

            // do your custom easing HERE with curKey

            var curKeyIndex = j+1;

        

            var easeIn = new KeyframeEase(0.5, 50);

            var easeOut = new KeyframeEase(0.75, 85);

curProp.setTemporalEaseAtKey(curKeyIndex, [easeIn], [easeOut]);

    }

}


Check out the docs on the KeyframeEase Object​ for scale and objects with multiple easing dimensions, you'll need to add easing to each dimension. Here's one way of solving it:

// Gets all properties with keyframes in a layer

function getPropsWithKeys(layer) {

    var numRootProps = layer.numProperties;

    var propsWithKeys = [];

    for (var i = 0; i < numRootProps; i++) {

        var prop = layer(i + 1);

        var isGroup = prop.numProperties && prop.numProperties > 0;

        if (isGroup) {

            for (var j = 0; j < prop.numProperties; j++) {

                var subProp = prop.property(j + 1);

                var isSubGroup =

                    subProp.numProperties && subProp.numProperties > 0;

                if (isSubGroup) {

                    for (var k = 0; k < subProp.numProperties; k++) {

                        var subSubProp = subProp.property(k + 1);

                        if (subSubProp.numKeys > 0) {

                            propsWithKeys.push(subSubProp);

                        }

                    }

                } else {

                    if (subProp.numKeys > 0) {

                        propsWithKeys.push(subProp);

                    }

                }

            }

        } else {

            if (prop.numKeys > 0) {

                propsWithKeys.push(prop);

            }

        }

    }

    return propsWithKeys;

}

// Usage

var keyedProps = getPropsWithKeys(app.project.activeItem.layers[1]);

for (var i = 0; i < keyedProps.length; i++) {

    var curProp = keyedProps;

    var numKeys = curProp.numKeys;

    for (var j = 0; j < numKeys; j++) {

        // do your custom easing HERE with curKey

        var curKeyIndex = j + 1;

        var easeIn = new KeyframeEase(0.5, 50);

        var easeOut = new KeyframeEase(0.75, 85);

        var easeDimensions = curProp.keyOutTemporalEase(curKeyIndex).length;

        if(easeDimensions === 1)

            curProp.setTemporalEaseAtKey(curKeyIndex, [easeIn], [easeOut]);

        else if(easeDimensions === 2)

            curProp.setTemporalEaseAtKey(curKeyIndex, [easeIn, easeIn], [easeOut, easeOut]);

        else if(easeDimensions === 3)

            curProp.setTemporalEaseAtKey(curKeyIndex, [easeIn, easeIn, easeIn], [easeOut, easeOut, easeOut]);

    }

}

1 reply

Known Participant
June 30, 2019

A bit of progress. I m able to iterate all comps layers and convert keyframes to ease but only for Position property. I need to apply it for all possible properties including effect props keys.

var proj = app.project;

var itemTotal = proj.numItems;

var curItem, curComp, totalComps, totalLayers, curLayer;

var itemAry = new Array ();

//iterate all items through project

for (var i = 1; i<= itemTotal; i++){

   

curItem = proj.item(i);

//check if current item is a comp

if(curItem instanceof CompItem){

   

    itemAry[itemAry.length] = curItem;

   

    }

   

   

    }

totalComps = itemAry.length;

for (var c = 0; c<totalComps; c++){

   

   

    curComp = itemAry;

    totalLayers = curComp.numLayers;

   

   

//loop layers + iterate all layers

   

    for (var l=1; l<=totalLayers; l++){

       

        curLayer = curComp.layer (l);

       

       

        var layerProp=curLayer.property("Position");

        var keyLength = layerProp.numKeys;

       

var vals = new Array();

for(var k=0; k<keyLength;k++){

   

    vals[vals.length] = layerProp.keyValue(k+1);

   

    var easeIn = new KeyframeEase(0.5, 50);

    var easeOut = new KeyframeEase(0.75, 85);

    var myKeyNumber = k+1;

   

    layerProp.setTemporalEaseAtKey(myKeyNumber, [easeIn], [easeOut]);

}

       

        }

   

   

    }

Justin Taylor-Hyper Brew
Community Expert
Community Expert
July 1, 2019

You're only looking at properties that match Position with curLayer.property("Position"). If you want all properties, then you'll need to loop through all properties in the layer like this:

// Gets all properties with keyframes in a layer

function getPropsWithKeys(layer){

    var numRootProps = layer.numProperties;

    var propsWithKeys = [];

    for (var i = 0; i < numRootProps; i++) {

        var prop = layer(i+1);

        var isGroup = prop.numProperties && prop.numProperties > 0;

        if(isGroup){

            for (var j = 0; j < prop.numProperties; j++) {

                var subProp = prop.property(j+1);

                var isSubGroup = subProp.numProperties && subProp.numProperties > 0;

                if(isSubGroup){

                    for (var k = 0; k < subProp.numProperties; k++) {

                        var subSubProp = subProp.property(k+1);

                        if(subSubProp.numKeys > 0){

                            propsWithKeys.push(subSubProp);

                        }

                    }

                }else{

                    if(subProp.numKeys > 0){

                        propsWithKeys.push(subProp);

                    }

                }

            }

        }else{

            if(prop.numKeys > 0){

                propsWithKeys.push(prop);

            }

        }

    }

    return propsWithKeys;

}

// Usage

getPropsWithKeys(app.project.activeItem.layers[1])

Known Participant
July 1, 2019

Thank you very much for help. Forgive my ignorence but i m stucked in how to implement this function to my script ?