Activity › Forums › Adobe After Effects Expressions › Display the name of the next visible layer below
-
Display the name of the next visible layer below
Posted by Mike Foran on May 10, 2017 at 1:27 pmHello all,
I am trying to figure a way to automatically display the name of the next visible layer below a text layer. I have figured out how to display the name of a layer directly below a text layer by using this expression in the source text:
thisComp.layer(index+1).name;But I’d love it if the expression could analyze the layer below it, determine of there is content there at that point in time, and if not continue analyzing each layer below until it finds content, then displays that layer name. Is that kind of action possible in an expression? Thanks.
Robert Anderson replied 7 years, 7 months ago 4 Members · 12 Replies -
12 Replies
-
Steve Sierra
May 10, 2017 at 2:23 pmHi,
I think this will work :
a = thisLayer.index;
b = thisComp.numLayers;
for(i = a+1; i <= b; i++){
curLay = thisComp.layer(i);
if(curLay.inPoint < time){
curLay.name;
break;
}
}Cheers !;)
-
Steve Sierra
May 10, 2017 at 2:29 pmThis is even better :
a = thisLayer.index;
b = thisComp.numLayers;
for(i = a+1; i <= b; i++){
curLay = thisComp.layer(i);
if(curLay.inPoint < time && curLay.outPoint > time){
curLay.name;
break;
}else{
“”
}
}😉
-
Mike Foran
May 10, 2017 at 3:04 pmEffing brilliant. If I might try to parse this so I understand what you are doing here, please let me know if I am getting it wrong.
– set a to the current layer index value
– set b to the total number of layers
– set a loop increasing i at each recursion from one over a until b
– set curLay to the name of the layer i
– check to see if the layer has an in point less than the current time
– if so display the nameWhat does the “break” command do?
Thanks for taking the time to do that!!
-
Steve Sierra
May 10, 2017 at 3:17 pmThat’s exactly it !
The “break” stops the for loop if a layer is found underneath the text layer.
The second expression also :
– checks if the outPoint is after time, so it stops displaying the name once the layer is cut.
– the else part makes the text layer display nothing (“”) if there is no layer underneath.Cheers !
😉 -
Mike Foran
May 10, 2017 at 3:18 pmThat is better but it was not getting the data for an edit until 1 frame after the in-point. I added the “=” back in to the in point check, so it’s like this:
a = thisLayer.index;
b = thisComp.numLayers;
for(i = a+1; i <= b; i++){
curLay = thisComp.layer(i);
if(curLay.inPoint <= time && curLay.outPoint > time){
curLay.name;
break;
}else{
“”
}
}Thanks again for taking the time on this. It will be very helpful for a number of projects.
-
Dan Ebberts
May 10, 2017 at 4:11 pmIf you’re only after visible layers this one should skip over nulls, audio layers, and anything with its eyeball turned off:
txt = "";
for (i = index+1; i <= thisComp.numLayers; i++){
L = thisComp.layer(i);
if (! (L.hasVideo && L.active && L.opacity > 0)) continue;
txt = L.name;
break;
}
txt
Dan
-
Mike Foran
May 10, 2017 at 4:35 pmExcellent Dan, thanks. If I might ask, what does the exclamation point in the IF statement do?
-
Dan Ebberts
May 10, 2017 at 4:39 pmIt means “Not”, so if anything in the parentheses isn’t true, the layer gets skipped.
Dan
-
Steve Sierra
May 10, 2017 at 5:03 pmVery nice !!
I didn’t know about the “continue”…
I see it stops the text layer from seeing the disabled layers.
Could you please explain how it works ?Many thanks 😉
-
Dan Ebberts
May 10, 2017 at 5:24 pm
Reply to this Discussion! Login or Sign Up