Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Count layers in a composition with a certain name

  • Count layers in a composition with a certain name

    Posted by Mathias Kalhauge on March 21, 2018 at 9:48 am

    Hey,
    so I know of the expression; thisComp.numLayers
    The problem with it is that it counts every layer. I want a sort of filter, that will only count the layers starting with a certain name. So:
    Layer_01
    Layer_02
    Layer_03
    Image_01
    Layer_04
    Image_02

    It only counts the two layers that start with “Image”.

    I’m not sure if it’s even possible – just wanted to know before I ruled it out as an option

    Blake Goulette replied 3 years, 8 months ago 3 Members · 2 Replies
  • 2 Replies
  • Andrei Popa

    March 21, 2018 at 10:53 am

    I don’t know if this is the most efficient method, but it works.
    layerNumber = 0;//start the counting of layers at 0
    layerStartWith = "Image";//the word with which the layers should start
    for(i=1;i<=thisComp.numLayers;i++){
    if (thisComp.layer(i).name.slice(0,layerStartWith.length) == layerStartWith) layerNumber =layerNumber +1;
    }
    layerNumber

    Andrei
    My Envato portfolio.

  • Blake Goulette

    September 9, 2022 at 9:47 pm

    It’s 4 years later but I just want to thank you for this!

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