Creative Communities of the World Forums

The peer to peer support community for media production professionals.

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

    Robert Anderson replied 7 years, 7 months ago 4 Members · 12 Replies
  • 12 Replies
  • Steve Sierra

    May 10, 2017 at 2:23 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 !;)

  • Steve Sierra

    May 10, 2017 at 2:29 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{
    “”
    }
    }

    😉

  • Mike Foran

    May 10, 2017 at 3:04 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!!

  • Steve Sierra

    May 10, 2017 at 3:17 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 !
    😉

  • Mike Foran

    May 10, 2017 at 3:18 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.

  • Dan Ebberts

    May 10, 2017 at 4:11 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

  • Mike Foran

    May 10, 2017 at 4:35 pm

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

  • Dan Ebberts

    May 10, 2017 at 4:39 pm

    It means “Not”, so if anything in the parentheses isn’t true, the layer gets skipped.

    Dan

  • Steve Sierra

    May 10, 2017 at 5:03 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 😉

  • Dan Ebberts

    May 10, 2017 at 5:24 pm

    It’s actually a variation of this:

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

    Dan

Page 1 of 2

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