Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Index of layer, counting only layers with specific name

  • Index of layer, counting only layers with specific name

    Posted by Noel Powell on June 5, 2023 at 1:22 am

    I have a comp with many layers. Some of those layers have “Control Layer” in their name. I’m looking for an expression to put on those layers, to get its number in the order. So if it’s the fifth control layer, it would give a result of 5, even if that layer’s actual index is higher.

    I really appreciate any guidance anyone can give me.

    Noel Powell replied 3 months, 4 weeks ago 3 Members · 5 Replies
  • 5 Replies
  • Dan Ebberts

    June 5, 2023 at 4:22 am

    Something like this:

    count = 0;
    for (i = 1; i <= index; i++){
    if (thisComp.layer(i).name.indexOf("Control Layer") == 0) count++;
    }
    count
  • Noel Powell

    June 5, 2023 at 12:39 pm

    That’s it, thanks so much Dan.

    I should add that as it is written, this expression works to find the order of the layer, counting only the layers whose names BEGIN with “Control Layer”. I should have specified my layers have “Control Layer” in the name, but they don’t start with that string of characters. I simply changed the “==” in the if statement to “>”, and it seems to do what I need now.

    Thanks again.

  • Brie Clayton

    June 5, 2023 at 1:53 pm

    Thank you for solving this issue, Dan!

  • Dan Ebberts

    June 5, 2023 at 4:29 pm

    In that case, I would change it to > -1

  • Noel Powell

    June 5, 2023 at 8:07 pm

    Great, I’ll do that. Thanks

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