Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Forums Adobe After Effects Expressions Targeting Arbitrary Layers in ExtendScript

  • Targeting Arbitrary Layers in ExtendScript

  • Ralph Moreau

    February 26, 2021 at 3:18 pm

    Hi all, Making a script that can allow me to ease my layers via shortcut. The problem I’m having is that I can’t seem to target a currently selected layer. I will share my code. Can anyone aid me with the logic of how to do this? I pretty much target with activeLay and numkeys. But I’ve only been successful at targeting the top layer. And a lot of efforts of changing up the target, using different methods. Please help if you can.

    var activeLay = app.project.activeItem; // mod piece for layer 1 of active layer

    //methods

    var numkeys = app.project.activeItem.layer(1).position.selectedKeys; // method that gives an array of all keyframes

    //numbers

    //keyframes

    //functiontotkeys active variables booleans\

    //---------------------------

    var posActive = false;

    var opaActive = false;

    var rotActive = false;

    var scaActive = false;

    var numAllKeys = 0; //will be the number of all keys

    var numPosKeys = new Array;

    var numRotKeys = new Array;

    var numOpaKeys = new Array;

    //------------------------------

    //~ ------------------ begin script

    functiontotalkeys(); // calling functiontotalkeys

    function functiontotalkeys() //this function will bring back all keys then call filterme

    {

    alert("hi");

    // formula call for position

    var checkPosKey = activeLay.position.numKeys; //checking number of 'position" keys on layer 1

    alert(checkPosKey);

    //alert("this is the position key " + checkPosKey);

    if (checkPosKey >= 1) // if there are any actual position keyframes then go ahead and iterate

    {

    for (var p = 1; p <= checkPosKey; p++)

    {

    alert("made it");

    //alert("for loop is being called");

    var keypos = app.project.item(2).layer(2).position.keySelected(p);

    alert(keypos);

    if(keypos == true)

    {

    alert(keypos + "HEYNOW");

    var posmod = activeLay.property("Position");// position layer module of active layer + layer 1

    var curPosKeyIn = activeLay.position.keyInTemporalEase(p)[0].influence;

    var curPosKeySp = activeLay.position.keyInTemporalEase(p)[0].speed;

    // //alert( "current influence is " + curPosKeyIn );

    var uniEasePos = new KeyframeEase( curPosKeySp ,(curPosKeyIn += 1));

    ////alert( "current influence is now " + curPosKeyIn );

    posmod.setTemporalEaseAtKey(p,[uniEasePos],[uniEasePos])

    }

    }

    };

    // formula call for rotation

    var checkRotKey = activeLay.rotation.numKeys; //checking number of 'position" keys on layer 1

    //alert("this is the position key " + checkRotKey);

    if (checkRotKey >= 1) // if there are any actual position keyframes then go ahead and iterate

    {

    for (var r = 1; r <= checkRotKey; r++)

    {

    //alert("for loop is being called");

    var keyrot = app.project.activeItem.layer(1).rotation.keySelected(r);

    if(keyrot == true)

    { var rotmod = activeLay.property("Rotation");// position layer module of active layer + layer 1

    var curRotKeyIn = activeLay.rotation.keyInTemporalEase(r)[0].influence;

    var curRotKeySp = activeLay.rotation.keyInTemporalEase(r)[0].speed;

    //alert( "current influence is " + curRotKeyIn );

    var uniEaseRot = new KeyframeEase( curRotKeySp ,(curRotKeyIn += 25));

    //alert( "current influence is now " + curRotKeyIn );

    rotmod.setTemporalEaseAtKey(r,[uniEaseRot],[uniEaseRot])

    }

    }

    };

    // formula call for scale

    var checkScaKey = activeLay.scale.numKeys; //checking number of 'position" keys on layer 1

    //alert("this is the position key " + checkScaKey);

    if (checkScaKey >= 1) // if there are any actual position keyframes then go ahead and iterate

    {

    for (var s = 1; s <= checkScaKey; s++)

    {

    //alert("for loop is being called");

    var keysca = app.project.activeItem.layer(1).scale.keySelected(s);

    if(keysca == true)

    { var scamod = activeLay.property("Scale");// position layer module of active layer + layer 1

    var curScaKeyIn = activeLay.scale.keyInTemporalEase(s)[0].influence;

    var curScaKeySp = activeLay.scale.keyInTemporalEase(s)[0].speed;

    //alert( "current influence is " + curScaKeyIn );

    var uniEaseSca = new KeyframeEase( curScaKeySp ,(curScaKeyIn += 25));

    //alert( "current influence is now " + curScaKeyIn );

    scamod.setTemporalEaseAtKey(s,[uniEaseSca,uniEaseSca,uniEaseSca],[uniEaseSca,uniEaseSca,uniEaseSca])

    }

    }

    };

    // formula call for rotation

    var checkOpaKey = activeLay.opacity.numKeys; //checking number of 'position" keys on layer 1

    //alert("this is the position key " + checkOpaKey);

    if (checkOpaKey >= 1) // if there are any actual position keyframes then go ahead and iterate

    {

    for (var o = 1; o <= checkOpaKey; o++)

    {

    //alert("for loop is being called");

    var keyopa = app.project.activeItem.layer(1).opacity.keySelected(o);

    if(keyopa == true)

    { var opamod = activeLay.property("Opacity");// position layer module of active layer + layer 1

    var curOpaKeyIn = activeLay.opacity.keyInTemporalEase(o)[0].influence;

    var curOpaKeySp = activeLay.opacity.keyInTemporalEase(o)[0].speed;

    //alert( "current influence is " + curOpaKeyIn );

    var uniEaseOpa = new KeyframeEase( curOpaKeySp ,(curOpaKeyIn += 25));

    //alert( "current influence is now " + curOpaKeyIn );

    opamod.setTemporalEaseAtKey(o,[uniEaseOpa],[uniEaseOpa])

    }

    }

    };

    }

  • Dan Ebberts

    February 26, 2021 at 3:47 pm

    Something like this should give you the first selected layer:

    var selectedLayers = app.project.activeItem.selectedLayers;

    if (selectedLayers.length > 0){

    var myLayer = selectedLayers[0];

    }else{

    alert("No layers selected.");

    }

  • Ralph Moreau

    February 26, 2021 at 4:53 pm

    Thank you Dan!!

Viewing 1 - 3 of 3 posts

Log in to reply.

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