FORUMS: list search recent posts

How to find the sum of the vectors inside a custom array?

COW Forums : Adobe After Effects

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Crystal Goh
How to find the sum of the vectors inside a custom array?
on Oct 25, 2019 at 6:55:45 am

Hi all, I am pretty new to expressions and trying to do an expression that finds the total width from my image layers ( which all have different widths, number of image layers not fixed).
My current issue is not knowing how to sum up the vectors inside the array I made. This stackflow thread has answered the question but when using their code, I still get errors: https://stackoverflow.com/questions/1230233/how-to-find-the-sum-of-an-array...

Would really appreciate any help!


// Variables
var myArray = [];
var i = 0;
var curLayer = thisComp.layer(i);

// Execution
for (; i<=thisComp.numLayers ; i++){
myArray.push(curLayer.sourceRectAtTime().width);
}

myArray.slice(2); /*Theres 2 layers in my comp that are not image layers, hence slicing them off.*/
//Next line am VERY unclear on getting the total width number with reduce()
return myArray.reduce(???);



Return to posts index

Dan Ebberts
Re: How to find the sum of the vectors inside a custom array?
on Oct 25, 2019 at 4:34:25 pm

I guess I'd do it like this:


accum = 0;
for (i = 3; i <= thisComp.numLayers; i++){
accum += thisComp.layer(i).sourceRectAtTime(time,false).width;
}
accum



Dan



Return to posts index

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