17 Replies Latest reply on Aug 9, 2017 9:17 PM by sravanp34392559

    Script to Rename Artboards with Layer Names

    sensibleworld

      I'm looking to create a script to batch rename a number of artboards.

       

      - I have 100 named layers.

      - I have 100 artboards.

      - I would like to rename the artboards to match the layer names.

      - The layers are organized in the same descending orderas the artboards (ignoring the actual artboard names*).

      - The topmost artboard (1 in the list) would be renamed "newspaper", the second artboard would be renamed "typewriter", the third artboard would be renamed "books", etc.

       

      *in the example below the artboard named "Artboard 7" is actually the 6th artboard in list.

      LayerNames-To-Artboards.png

       

      Any help would be wonderful.

        • 1. Re: Script to Rename Artboards with Layer Names
          ThinkingThings Level 1

          That's neat. What do you have so far in the way of a script or what questions/problems are you encountering?

          • 2. Re: Script to Rename Artboards with Layer Names
            sensibleworld Level 1

            To be honest, I'm completely new to scripting (much more of a designer than a developer), and am hoping to either be pointed to a script that does something similar that I could fiddle with, or to have someone help me create it.

             

            It was suggested that I should pose the question here (even though asking for someone to create the script for me is frowned upon). So, apologies for that

            • 3. Re: Script to Rename Artboards with Layer Names
              W_J_T Level 4

              Hi sensibleworld, welcome to the forum.

               

              For your case it should be pretty straight forward. The following little script snippet will rename the artboards to match the corresponding layer names as you described in your first post above. It only works if the number of layers and artboards match as shown and talked about in your above description of requirements.

               

              if (app.documents.length == 0) {
                  alert("No Open / Active Document Found");
              } else {
                  var doc = app.activeDocument;
                  if (doc.artboards.length == doc.layers.length && doc.layers.length == doc.artboards.length) {
                      for (var i = 0, l = doc.artboards.length; i < l; i++) {
                          var ab = doc.artboards[i];
                          ab.name = doc.layers[i].name;
                      }
                      alert("Finished:\nRenaming of Artboards to match Layer names is complete");
                  } else {
                      alert("Opps: This wont work!\n The number of Layers and Artboards do not match");
                  }
              }
              

               

              I hope it proves useful to your efforts and requirements. Again welcome to the forum.

              • 4. Re: Script to Rename Artboards with Layer Names
                sensibleworld Level 1

                Worked like a charm! Thank you, thank you, thank you.

                • 5. Re: Script to Rename Artboards with Layer Names
                  W_J_T Level 4

                  You're welcome, glad it helped.

                   

                  Hopefully it might be useful to someone else down the road as well with a similar situation.

                   

                  Oops, I spelled oops (opps) wrong in my script 

                  • 6. Re: Script to Rename Artboards with Layer Names
                    sensibleworld Level 1

                    First of all, thank you for all of the help on this script (from over a year ago!).

                     

                    I'm working on another project and a similar question popped up. I wonder if it's possible to tweak the script so that it ignored the order of the artboards/layers, but instead focused on the relationship between layer and artboard.

                     

                    So, in this variation:

                     

                    - Each artboard has a name.

                    - Each layer NEEDS a name.

                    - There are an equal number of layers and artboards.

                    - Only one layer "exists" on each artboard. (i.e. They share coordinates.)

                    - I would like to name the layer with the same name as its encompassing artboard.

                     

                    Is this possible? Am I crazy? (They may not be mutually exclusive.)

                    • 7. Re: Script to Rename Artboards with Layer Names
                      W_J_T Level 4

                      You probably should have started a new thread. ;-)

                      sensibleworld wrote:

                       

                      First of all, thank you for all of the help on this script (from over a year ago!).

                       

                      I'm working on another project and a similar question popped up. I wonder if it's possible to tweak the script so that it ignored the order of the artboards/layers, but instead focused on the relationship between layer and artboard.

                       

                      So, in this variation:

                       

                      - Each artboard has a name.

                      - Each layer NEEDS a name.

                      - There are an equal number of layers and artboards.

                      - Only one layer "exists" on each artboard. (i.e. They share coordinates.)

                      - I would like to name the layer with the same name as its encompassing artboard.

                       

                      Is this possible? Am I crazy? (They may not be mutually exclusive.)

                       

                      If each layer has at least a single item on it (not empty) then the following should do what you described (if I understood correctly). It worked in my test of your described situation.

                       

                      function artboardLayerNameMatch() {
                          if (app.documents.length == 0) {
                              alert("No Open / Active Document Found");
                          } else {
                              var doc, i, l, ab, sel, n;
                              doc = app.activeDocument;
                              for (i = 0, l = doc.artboards.length; i < l; i++) {
                                  ab = doc.artboards[i];
                                  doc.artboards.setActiveArtboardIndex(i);
                                  doc.selectObjectsOnActiveArtboard();
                                  sel = doc.selection[0];
                                  sel.parent.name = ab.name;
                                  doc.selection = false;
                              }
                          }
                      }
                      artboardLayerNameMatch();
                      

                       

                      Hope it helps your efforts.

                       

                      PS: As for being crazy, perhaps we all are to a certain degree, willingly living under the Adobe tyranny.

                      1 person found this helpful
                      • 8. Re: Script to Rename Artboards with Layer Names
                        sensibleworld Level 1

                        Worked like a charm! Thank you so much.

                         

                        And yeah, after I posted, I realized a new thread would have made more sense. It shall not happen again!

                        • 9. Re: Script to Rename Artboards with Layer Names
                          W_J_T Level 4

                          You're welcome, glad it worked out for you.

                          • 10. Re: Script to Rename Artboards with Layer Names
                            denisepotts

                            This works fantastically.  Thank you.  My question is, is there a way to reverse the order of the layers first?  I have my layers building from the bottom up on many files. 

                             

                            1. Screen 1

                            then above that is the layer

                            2. Screen 2

                             

                            So when I run this script it, names all of my artboards in reverse order.

                             

                            Thanks!

                            • 11. Re: Script to Rename Artboards with Layer Names
                              brucechristyalliance

                              I wonder if someone could instruct me how to take this snippet and put it into a script I can put into Illustrator. I did copy / paste into script editor, but it doesn't seem to take in Adobe Illustrator 2015 CC. Help?

                               

                              Thanks.

                              • 12. Re: Script to Rename Artboards with Layer Names
                                williamadowling Level 4

                                brucec11727021 wrote:

                                 

                                I wonder if someone could instruct me how to take this snippet and put it into a script I can put into Illustrator. I did copy / paste into script editor, but it doesn't seem to take in Adobe Illustrator 2015 CC. Help?

                                 

                                Thanks.

                                 

                                Option 1:

                                You can save the file as a .js or .jsx and access it via "File > Scripts > Other Script" then navigate to wherever you saved the script and run it that way. This option is best if you only plan on running the script once or twice.

                                 

                                Option 2:

                                You can save the file as a .js or .jsx into the application's scripts folder which will be located in: "Applications > Adobe Illustrator (Version number) > presets > en_us (or whatever language you've installed) > Scripts. Once you save the script into that folder, you'll have to re-launch illustrator. Then the script will show up in the "File > Scripts" list and you can execute the script from there. This option is best if you are going to use the script regularly as it will always be available in your File > Scripts menu.

                                 

                                Option 3:

                                You can paste the code into ExtendScript ToolKit and execute the code from inside the IDE. This is best if you are going to be modifying the code and you'll need to debug on the fly.

                                • 13. Re: Script to Rename Artboards with Layer Names
                                  WallyDee Level 1

                                  I realize I'm a little late with this reply but just in case anyone else might have the same question...

                                  denisepotts  wrote

                                   

                                  My question is, is there a way to reverse the order of the layers first?

                                  Yes. In the Layers Panel, click on the first layer then shift-click on the last layer in order to 'highlight' them then go to the Layer Panel Options:

                                  VTiyH.png

                                  From there, choose 'Reverse Order':

                                  wFyAb.png

                                  • 14. Re: Script to Rename Artboards with Layer Names
                                    sensibleworld Level 1

                                    Wondering if the reverse of the above script is possible?

                                     

                                    The new scenario is:

                                    • Each layer has a name.
                                    • Each artboard NEEDS a name.
                                    • There are an equal number of layers and artboards.
                                    • Only one layer "exists" on each artboard. (i.e. They share coordinates.)
                                    • I would like to name the artboard with the same name as the layer that resides “on” it.

                                     

                                    Here's the original for reference:

                                     

                                    function artboardLayerNameMatch() {  
                                        if (app.documents.length == 0) {  
                                            alert("No Open / Active Document Found");  
                                        } else {  
                                            var doc, i, l, ab, sel, n;  
                                            doc = app.activeDocument;  
                                            for (i = 0, l = doc.artboards.length; i < l; i++) {  
                                                ab = doc.artboards[i];  
                                                doc.artboards.setActiveArtboardIndex(i);  
                                                doc.selectObjectsOnActiveArtboard();  
                                                sel = doc.selection[0];  
                                                sel.parent.name = ab.name;  
                                                doc.selection = false;  
                                            }  
                                        }  
                                    }  
                                    artboardLayerNameMatch();  
                                    
                                    • 15. Re: Script to Rename Artboards with Layer Names
                                      williamadowling Level 4

                                      While this is somewhat related to the original post, it would be a good idea to post a new topic with your question. You're more likely to get more answers and it will help anyone who has the same question in the future find the discussion.

                                      • 17. Re: Script to Rename Artboards with Layer Names
                                        sravanp34392559

                                        Hi,

                                        My requirement is the same, but instead of layers it is the Layer Comps.

                                        I'd like to give the Layer Comp names(PS) to the Art boards in Illustrator CC

                                        Could someone please help with this! Thanks