Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Loop Through Layer Controls and Retrieve Position/Rotation Values

  • Loop Through Layer Controls and Retrieve Position/Rotation Values

    Posted by Dave Currie on October 30, 2017 at 4:34 am

    Hello this is probably an easy fix but I can’t seem to get the syntax correct.

    I need to loop through 10 layers which are set with layer expression controls, retrieve the position or rotation values of each layer and store those values in an array. I’m using a try/catch so it doesn’t throw an error if no layer is set.

    All I need to do is increment the number in the effect name but I’m getting hung up on what seems like a simple bit of code. Also, is there a way to combine the two separate loops into a single loop?

    targetLayers = new Array();
    for (var i=0; i<10; i++){
    myStr1 = 'effect("My Effect")("Target Layer ';
    myStr2 = '")'
    t = i+1;
    try{
    targetLayers[i] = myStr1+t+myStr2;
    }catch (err){
    targetLayers[i] = "";
    }
    }
    var layerPos = new Array();
    for (var i=0; i<10; i++){
    try{
    layerPos[i] = targetLayers[i].transform.position;
    }catch (err){
    layerPos[i] = [0,0,0];
    }
    }

    Dan Ebberts replied 8 years, 9 months ago 2 Members · 1 Reply
  • 1 Reply
  • Dan Ebberts

    October 30, 2017 at 7:19 am

    I’d think you could do something like this:


    layerPos = [];
    for (i = 0; i < 10; i++){
    try{
    L = effect("My Effect")("Target Layer " + (i+1));
    layerPos.push(L.position.value);
    }catch(err){
    layerPos.push([0,0,0]);
    }
    }

    Dan

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