ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Count layers in a composition with a certain name

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Mathias Kalhauge
Count layers in a composition with a certain name
on Mar 21, 2018 at 9:48:52 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


Return to posts index

Andrei Popa
Re: Count layers in a composition with a certain name
on Mar 21, 2018 at 10:53:54 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.


Return to posts index

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