Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Forums Adobe After Effects Expressions ExtendScript, refer to the layer by name

  • ExtendScript, refer to the layer by name

  • Vitaliy Grebennikov

    July 2, 2021 at 9:49 pm

    Hi!
    Started writing simple scripts for After effects, it’s very interesting and useful for my work. But I was already desperate to find a simple formula that would refer to the layer by name, but I cannot write it myself at the moment.

    This is my stopper, I just can’t go beyond this moment.
    If someone can help me, I will be extremely grateful !!!

  • Vitaliy Grebennikov

    July 3, 2021 at 12:58 am

    This script don’t work for me(

    I tested it – tried to make layer with specific name to be labeled with some colour, but it doesn’t work…

    var proj = app.project;

    var itms = proj.items;

    var itmsLen = itms.length;

    var curItem, myComp;

    for(var i=0; i<itmsLen; i++){

    curItem = itms;

    If(curItem instanceof CompItem){

    If(curItem.name == “your comp name”){ //Will grab only the first name match

    myComp = curItem;

    break;

    }

    }

    }

    var chkLayer = myComp.layer(“Layer Name”);

    if (chkLayer == undefined){

    //do this

    }else{

    //do that

    }

  • Andrei Popa

    July 3, 2021 at 2:58 pm

    It seems more likely that the problem is in selecting the composition. Try to select the layer like this and see if it works. Before running the script, select your comp either in the project panel or just select the timeline.

    var myComp = app.project.activeItem;
    var chkLayer = myComp.layer("Layer Name");
  • Vitaliy Grebennikov

    July 15, 2021 at 8:21 am

    Thx for your attention, Andrei!

    I figured out why this formula didn’t work.

    I tried to figure out this problem for a long time, went through many options, nothing worked, but it gave me a basic understanding of the patterns, and it turned out that the author posted this code simply with syntax errors (apparently, some text editor messed up the text).

    Here is a working formula (I added a little to it so as not to mention the name several times.

    var proj = app.project;
    var itms = proj.items;
    var itmsLen = itms.length;
    var curItem = myComp;
    var layerName = "/YOUR LAYER NAME/";
    for(var i=0; i<itmsLen; i++){
    curItem = itms;
    if(curItem instanceof CompItem){
    if(curItem.name == layerName ){ //Will grab only the first name match
    myComp = curItem;
    break;
    }
    }
    }
    var chkLayer = myComp.layer(layerName );
    if (chkLayer == undefined){
    //do something
    }else{
    //do something else
    }
Viewing 1 - 4 of 4 posts

Log in to reply.

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