Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects I have a problem about loop and array

  • I have a problem about loop and array

    Posted by Supak Suksawat on October 15, 2021 at 7:02 am

    ——————————————————————————–

    var layersList = app.project.activeItem.selectedLayers;

    var o=[layersList];

    for (i=0;i<layersList.length;i++){

    checkNAME[i]=layersList[i].name;

    checkNAME2[i]=layersList[i].name;

    index=checkNAME[i].lastIndexOf (“-“);

    if(index>=0){

    checkNAME[i]= checkNAME[i].substring (0, index);

    }

    if(checkNAME2[i].indexOf(checkNAME[i])!==-1){

    if(checkNAME2[i].indexOf(“1”,index)>-1){ <—-1

    o[i]=layersList[i];

    }

    }

    }

    for(i=0;i<layersList.length;i++){

    if(o[i]==null){

    continue;

    }

    if(layersList[i].name==o[i].name){

    continue;

    }

    alert(layersList[i].name);<—-2

    }

    —————————————————————————————-

    I try to use loop to collect layers to array of o and I want get the layer that have name like point 1 and put it and show the layer that not like 1 at 2 but it don’t show anything to me.

    such as, I have layer A 01-1, A 01-2, A 01-3, B 01-1, B 01-2, B 01-3, B 01-4

    It should be show A 01-2, A 01-3 and B 01-2, B 01-3, B 01-4

    Meng Zhiqun replied 4 years, 6 months ago 2 Members · 1 Reply
  • 1 Reply
  • Meng Zhiqun

    October 30, 2021 at 1:08 pm

    I tried hard to understand what did you want to do with your script. With the best of my ability, I think what you need, is to get an array of layers that has a certain string in the layer’s name.

    Here’s a function you can use instead.

    var proj = app.project;

    var projComp = app.project.activeItem;

    var selLay = projComp.selectedLayers;

    function getLay(searchNameForthis){

    var getLay = [];

    for(var i = 0; i <= selLay.length-1; i++){

    var curLay = selLay[i];

    if(curLay.name.toLowerCase().indexOf(searchNameForthis) != -1){

    getLay.push(curLay);

    }

    }

    if(getLay.length > 0){

    return getLay;

    }else{

    return 0;

    }

    }

    alert(getLay("solid"));

    You can replace the “Solid” in getLay(“Solid”); with any string that you wish to find the names by and this function will give you the layers. Hope this helps.

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