ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Loop Through Layer Controls and Retrieve Position/Rotation Values

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Dave Currie
Loop Through Layer Controls and Retrieve Position/Rotation Values
on Oct 30, 2017 at 4:34: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&lt;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&lt;10; i++){
try{
layerPos[i] = targetLayers[i].transform.position;
}catch (err){
layerPos[i] = [0,0,0];
}
}


Return to posts index

Dan Ebberts
Re: Loop Through Layer Controls and Retrieve Position/Rotation Values
on Oct 30, 2017 at 7:19:53 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



Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]