5 Replies Latest reply on Sep 27, 2013 10:38 AM by Tiago Cotrim

    Renumber/Batch rename layers

    pavelfuksa Level 1

      Hi, is there a quick way how to renumber or batch rename all layers in a file so they would be named in consequent numbers? Doesn't have to start from exact number, I was wondering if maybe there is some sort of script that would help me with that? Thanks a lot

        • 1. Re: Renumber/Batch rename layers
          JETalmage Level 6

          The simple Javascript below seems to work fine in CS3. It renames existing Layers and Sublayers down to two Sublayer levels, according to their current stacking order, using dot-syntax.

           

           

           

           

          ////START SCRIPT////

          docRef=app.activeDocument;
          topLayers=docRef.layers;
          for(i=0;i<topLayers.length;i++){
          var currLayer=topLayers[i];
          var newNum=i+1;
          currLayer.name="Layer "+newNum;
          subLayers=topLayers[i].layers;
          for(j=0;j<subLayers.length;j++){
            var currSubLayer=subLayers[j];
            var newSubNum=j+1;
            currSubLayer.name="Layer "+ newNum+"."+newSubNum;
            subSubLayers=subLayers[j].layers;
             for(k=0;k<subSubLayers.length;k++){
              var currSubSubLayer=subSubLayers[k];
              var newSubSubNum=k+1;
              currSubSubLayer.name="Layer "+ newNum+"."+newSubNum+"."+newSubSubNum;
             }
            }
          }

          ////END SCRIPT////

           

          To use it:

          1. Copy the lines of script.

          2. Paste into a text editor.

          3. Save as plain text, titling the file, including the file extension as: JET_X_RenumberLayers.jsx

          4. Quit Illustrator.

          5. Put the file in Illustrator's Presets/Scripts folder.

          6. Launch Illustrator. The script should appear in the File>Scripts submenu.

           

          JET

          • 2. Re: Renumber/Batch rename layers
            steven1978leon Level 1

            This script is so useful.

             

            Could you help me with one thing? How to start the number from the bottom layer?

             

            Thanks for your time.

            • 3. Re: Renumber/Batch rename layers
              hoovdan

              This thread is kind of old, but I found JET's script to be extremely useful, and like Steven, I also needed it to start from the bottom layer.  So I updated it a little.

               

              Set "fromTop" to "true" if you want it to name the top-most layer #1.

              Set "fromTop" to "false" if you want the bottom-most layer to be #1.

               

               

              ////START SCRIPT////

              #target Illustrator

               

              var docRef = app.activeDocument;

              var fromTop = true;                 

                      // if true,  the top layer will be #1

                      // if false, the bottom layer will #1

               

              renumberLayers(fromTop);

               

               

              function renumberLayers(fromTop){

                  var topLayers = docRef.layers;

               

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

                      var currLayer = topLayers[i];

               

                      if(fromTop) var newNum = i + 1;

                      else var newNum = topLayers.length - i;

               

                      currLayer.name="Layer "+newNum;

                      subLayers= topLayers[i].layers;

               

                      for(j=0; j<subLayers.length; j++){

                          var currSubLayer = subLayers[j];

                          var newSubNum = subLayers.length - j;

               

                          currSubLayer.name="Layer "+ newNum+"."+newSubNum;

               

                          subSubLayers=subLayers[j].layers;

               

                          for(k=0; k<subSubLayers.length; k++){

               

                              var currSubSubLayer = subSubLayers[k];

                              var newSubSubNum = subSubLayers.length - k;

               

                              currSubSubLayer.name="Layer "+ newNum+"."+newSubNum+"."+newSubSubNum;

                          }

                      }

                  }

              }

               

              ////END SCRIPT////

              • 4. Re: Renumber/Batch rename layers
                bradonwebb

                What about to rename ONLY the selected layers?

                 

                and also what about to rename ONLY the selected layers IN THE ORDER they were selected?

                • 5. Re: Renumber/Batch rename layers
                  Tiago Cotrim

                  bradonwebb wrote:

                   

                  What about to rename ONLY the selected layers?

                   

                  and also what about to rename ONLY the selected layers IN THE ORDER they were selected?

                   

                  I would love the option to rename only the selected layers! But the other scripts where really helpful, thank you!