ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Display the name of the next visible layer below

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Mike Foran
Display the name of the next visible layer below
on May 10, 2017 at 1:27:41 pm

Hello 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.


Return to posts index

Steve Sierra
Re: Display the name of the next visible layer below
on May 10, 2017 at 2:23:00 pm

Hi,

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 !;)


Return to posts index

Steve Sierra
Re: Display the name of the next visible layer below
on May 10, 2017 at 2:29:19 pm

This 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{
""
}
}

;)


Return to posts index


Mike Foran
Re: Display the name of the next visible layer below
on May 10, 2017 at 3:18:05 pm

That 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.


Return to posts index

Mike Foran
Re: Display the name of the next visible layer below
on May 10, 2017 at 3:04:29 pm

Effing 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 name

What does the "break" command do?

Thanks for taking the time to do that!!


Return to posts index

Steve Sierra
Re: Display the name of the next visible layer below
on May 10, 2017 at 3:17:34 pm

That'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 !
;)


Return to posts index


Dan Ebberts
Re: Display the name of the next visible layer below
on May 10, 2017 at 4:11:09 pm

If 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



Return to posts index

Mike Foran
Re: Display the name of the next visible layer below
on May 10, 2017 at 4:35:04 pm

Excellent Dan, thanks. If I might ask, what does the exclamation point in the IF statement do?


Return to posts index

Dan Ebberts
Re: Display the name of the next visible layer below
on May 10, 2017 at 4:39:24 pm

It means "Not", so if anything in the parentheses isn't true, the layer gets skipped.

Dan



Return to posts index


Steve Sierra
Re: Display the name of the next visible layer below
on May 10, 2017 at 5:03:27 pm

Very 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 ;)


Return to posts index

Dan Ebberts
Re: Display the name of the next visible layer below
on May 10, 2017 at 5:24:34 pm

It's actually a variation of this:

http://motionscript.com/design-guide/source-name.html


Dan



Return to posts index

Mike Foran
Re: Display the name of the next visible layer below
on May 10, 2017 at 5:25:24 pm

I presume the "hasVideo" and "active" return a 1 if True, and Opacity anything over 0 would be visible, so if all three of those attributes are 0 then it sets the string to the name of the layer. Otherwise it remains blank, as set in the opening line, and checks the next layer.


Return to posts index


Robert Anderson
Re: Display the name of the next visible layer below
on Oct 3, 2018 at 12:22:34 am

you really only need the below code to get what you want quickly and simply
Index is the layer number
Add one for next layer number
refer to that layer with "thisComp.layer()"
and the .name prefix will return the name

Everything else just makes the code scaleable so that you can redeploy if in other projects.
But if its just the next layer you want, one time thing, just use the simple code.


To reply to the above your maths is right, and logic is right.
But the result is the other way around from what you have. If all are 0 then there is nothing visible and it will continue through the loop to find the first visible instance.

i=thisLayer.index+1;
n=thisComp.layer(i).name;


Return to posts index

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