8 Replies Latest reply on Aug 28, 2013 8:57 AM by michael_mandahl

    Batch layer renaming

    H0usemaster

      Hi there,

       

      I've run into a little problem moving forward with a project, I've got quite a few files, each of them has about 15 layers.

       

      These layers contain underscores "_" in the name, which all need to be replaced with a hyphen "-".

      Is it possible to have a script do this? And if so, how would I go about writing one? Or even better - could I get one that is already written!

       

      Thanks a bunch.

        • 1. Re: Batch layer renaming
          W_J_T Level 4

          Welcome to the forum.

          H0usemaster wrote:

           

          layers contain underscores "_" in the name, which all need to be replaced with a hyphen "-".

           

          Maybe this will help get you started:

           

          var doc = app.activeDocument;
          for (var i = 0, l = doc.layers.length; i < l; i++) {
              doc.layers[i].name = doc.layers[i].name.split('_').join('-');
          }
          
          • 2. Re: Batch layer renaming
            H0usemaster Level 1

            Thanks a bunch - I hate to ask a probably obvious question - but as I don't speak script, when you say "help you get started" are you being ironic and, have in fact, provided complete code?

            • 3. Re: Batch layer renaming
              CarlosCanto Adobe Community Professional & MVP

              I don't see the irony, and yes, it is a complete code.

              • 4. Re: Batch layer renaming
                W_J_T Level 4

                H0usemaster wrote:

                 

                Thanks a bunch - I hate to ask a probably obvious question - but as I don't speak script, when you say "help you get started" are you being ironic and, have in fact, provided complete code?

                 

                You're welcome.

                 

                Well it's complete in the sense that it will do what you asked. You do still however need to manually open each illustrator file and run the script, but when doing so all underscores will be changed to hyphens in all the layer names. Just copy the code into a text editor and save it as something like renameLayers.js , then when you open each document go under File -> Scripts -> Other Scripts to locate and execute the script. It will do what you want and was a starting point, of course it could be automated further but it was a quickie that should fit your needs from having to manually change the layer names like you asked. ;-)

                 

                If it's helpful to your needs mark the answer/thread as correct.

                • 5. Re: Batch layer renaming
                  Larry G. Schneider Adobe Community Professional & MVP

                  Yes, it works as requested. Copy the above, paste it into a new ESTK window and save. Put the resulting file into HD/Applications/Adobe Illustrator CSX/Presets/en_US/Scripts and restart AI to make it available from File>Scripts.

                  1 person found this helpful
                  • 6. Re: Batch layer renaming
                    H0usemaster Level 1

                    i·ro·ny 

                    /ˈīrənē/

                    The expression of one's meaning by using language that normally signifies the opposite.

                     

                    In this case, W_J_T said:

                     

                     

                    W_J_T wrote:


                    Maybe this will help get you started:

                     

                    When he has written precisely the script I asked for - thus finishing what I had set out to achieve.

                    hence irony.

                     

                    But thank you for your contribution.

                    • 7. Re: Batch layer renaming
                      W_J_T Level 4

                      I was not being ironic at all when I stated "Maybe this will help get you started".

                       

                      As I mentioned in my followup post, it was a quick code snippet that will do exactly what you want but was merely a starting point as well. Meaning it could be extended further to literally batch process a folder with 1000 Illustrator files, run the script, select the folder and when it executes it automatically opens up each file, renames the layers and saves the file, etc., that's all I meant with "get you started". It will do everything you asked, but could be extended further as well. Glad you found it helpful regardless. ;-)

                       

                      Thanks Carlos and Larry.

                      • 8. Re: Batch layer renaming
                        michael_mandahl

                        This works great if you have mulitple layers that need to be renamed!

                         

                        var doc = app.activeDocument;

                        for (var i = 0, l = doc.layers.length; i < l; i++) {     doc.layers[i].name =      doc.layers[i].name.split('layer1').join('Layer1_DO NOT PRINT');

                        }

                        for (var i = 0, l = doc.layers.length; i < l; i++) {     doc.layers[i].name =      doc.layers[i].name.split('layer2').join('Layer2_PRINT');

                        }