-
Check for existence of specific layer name from top to bottom of comp
I’ve found an expression which almost does what I’m looking for here:
https://forums.creativecow.net/thread/227/6932
Here’s the expression, slightly modified:
findName = "Fred";
for (i =index; i <=thisComp.numLayers; ++i) {
if (thisComp.layer(i).name.indexOf(findName) != -1) {
// do what you need for this;
}
}
It successfully finds a layer of name “Fred”, and by simply looking at the variable i, returns the layer number, which is exactly what I want. But if I have several layers named Fred 1, Fred 2, Fred 3, it always returns the number of the layer lowest in the comp stack, which seems really odd, seeing as the code seemingly starts at layer index (the layer with this expression is always ABOVE the Fred layer), increases by 1 on each iteration, then does the “// do what you need for this;” when it’s reached the appropriate layer. But seemingly the loop continues until it finds the highest number…or something.I’m looking to find the next layer BELOW the current one (the one with the expression), so if I have, in my comp, the layers:
1 nothing
2 layer with expression
3 not important
4 something else
5 Fred 1
6 another irrelevant layer
7 Fred 2
8 background or something
…then I’d like the “layer with expression” to search downwards, and stop the search when it reaches the first Fred layer; in this case layer 5. But I have no idea why this expression is not doing this. Any suggestions, please?motion graphics | VFX | web design | etc.
https://paulroper.com/