ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Add up the heights of however many layers are present?

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Chris Biagi
Add up the heights of however many layers are present?
on Apr 29, 2019 at 6:46:46 pm
Last Edited By Chris Biagi on Apr 29, 2019 at 6:48:24 pm

Hi!

I'm building a template for which I need to know the total of all the text layers' heights in pixels, by adding up all their sourceRectAtTime(0).height values. The template consists of a variable number of text layers, which are arranged on multiple lines, centered horizontally. Just a standard title screen basically.

I have a general idea of how the logic could work, but I'm not quite sure where to start with this. The number of lines of text will vary, which the template must accommodate automatically. Ultimately I will use the total height of all the lines of text to calculate how to center the block of multiple text layers vertically.

I've named all my text layers like, "TXT - name". I use name.split(" - ")[0] to detect the string "TXT," to determine which layers are designated as text layers.

I believe I can use the code above as a basis to count how many "TXT" layers exist. Then I can use that value to tell AE which layer indexes' heights need to be added up. Something like,

If there are 2 Text layers detected, add up the heights of layer 1 + layer 2

If there are 4 Text layers detected, add up the heights of layer 1 + layer 2 + layer 3 + layer 4

etc...


Thanks


Return to posts index

Dan Ebberts
Re: Add up the heights of however many layers are present?
on Apr 29, 2019 at 7:26:22 pm

This would be the general idea:


h = 0;
for (i = 1; i <= thisComp.numLayers; i++){
if (i == index) continue;
if (thisComp.layer(i).name.split(" - ")[0] != "TXT") continue;
h += thisComp.layer(i).sourceRectAtTime(time,false).height;
}
h



Dan



Return to posts index

Chris Biagi
Re: Add up the heights of however many layers are present?
on Apr 29, 2019 at 8:37:11 pm

Looks like I'll have to go do some tutorials on "For" loops, that's new to me. I'll update once I have this working, thanks Dan.


Return to posts index

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