Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Getting active layer count at current time

  • Getting active layer count at current time

    Posted by Fletcher Groeneman on August 14, 2014 at 9:24 pm

    Hello CreativeCow community!

    I am trying to have a text layer’s Source Text be the number of active layers above itself at the current time.

    The number would change as you scrub through the timeline and more or less layers become visible.

    Thank you for your help!

    Brie Clayton replied 8 months, 1 week ago 5 Members · 11 Replies
  • 11 Replies
  • Dan Ebberts

    August 14, 2014 at 10:09 pm

    Try this:


    n = 0;
    for (i = 1; i < index; i++)
    if (thisComp.layer(i).active)
    n++;
    n

    Dan

  • Fletcher Groeneman

    August 14, 2014 at 10:13 pm

    Works perfect. Dan, you are the best!

    Many, many thanks.

    If you have time, could you walk me through that expression… I would love to understand what is happening so I can modify and re-use it in future work.

    – Fletcher Groeneman

  • Dan Ebberts

    August 14, 2014 at 10:32 pm

    Fletcher,

    The expression just looks at each layer that has a layer index less than its own (which means the other layer is above the layer with the expression in the layer stack) and bumps a counter (n) for each active layer it finds.

    Dan

  • Fletcher Groeneman

    August 14, 2014 at 10:47 pm

    Thanks Dan.

    So let me try and interpret it:

    for (incrementally by 1; every layer index smaller than my index)
    if (that layer is active)
    add 1 to a start value of 0

    Correct?

    – Fletcher Groeneman

  • Dan Ebberts

    August 14, 2014 at 10:51 pm

    That’s it!

  • René Pedersen

    December 7, 2022 at 2:22 pm

    Hi

    The last couple of days I have been – unsuccessfully – trying to expand this old expression.

    The thing is that I don’t want to count active layers, but count all layers that has the term BlueBox in its name.

    I remembered an expression I had used before from that uses a keyword (not to get a number, but to set a width) https://ukramedia.com/how-to-automatically-get-the-size-of-many-layers/

    keyword = “ukramedia”;

    widthList = [];

    for(i = 1; i <= thisComp.numLayers; i++) {

    layerPath = thisComp.layer(i);

    layerWidth = layerPath.sourceRectAtTime().width;

    if(layerPath.name.match(keyword)) {widthList.push(layerWidth)} else {};

    }

    Math.max(…widthList) + 100

    
    

    But when I try to merge the expressions it doesn’t work. This is what I tried – any idea what am I doing wrong?

    n = 0;

    keyword = “BlueBox”

    for (i = 1; i < index; i++)

    layerPath = thisComp.layer(i)

    if (layerPath.name.match(keyword))

    n++;

    
    
    		
        
  • Dan Ebberts

    December 7, 2022 at 5:11 pm

    This should count all layers with BlueBox in the layer name:

    n = 0;
    keyword = "BlueBox";
    for (i = 1; i <= thisComp.numLayers; i++){
    if (thisComp.layer(i).name.indexOf(keyword) > -1) n++;
    }
    n
  • Penelope Harpley

    October 4, 2023 at 2:35 am

    Hello all,

    I’ve been trying to rejig the expressions in this post to work for my needs to no avail. Maybe I’m barking up the wrong tree? My javascript knowledge is minimal.

    I’m trying to accumulate the width of multiple layers if they meet a condition.

    In basic english:

    Look through all layers with an index < current layer. If the opacity == 100, get width of current layer and add to a total.

    Thanks in advance!

  • Dan Ebberts

    October 5, 2023 at 7:31 pm

    Like this maybe:

    total = 0;
    for (i = 1; i < index; i++){
    if (thisComp.layer(i).opacity == 100){
    total += thisComp.layer(i).sourceRectAtTime(time,false).width;
    }
    }
    total
  • Penelope Harpley

    October 13, 2023 at 1:14 am

    Dan, thank you so much this works! You are a legend. I have learned so much from your work with expressions over the years, I can’t thank you enough for your contribution to this forum.

Page 1 of 2

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