5 Replies Latest reply on Jul 27, 2018 10:19 AM by zymox

    Script to Sort Artboard List Alphabetically

    sensibleworld

      I'm on the lookout for a simple script to sort an Illustrator artboard list alphabetically. (I don't need the artboards themselves rearranged on the canvas, just the order of the artboards in the list.)

       

      In the example (image) below, the artboard list reads:

       

      1. life-ring

      2. wheelchair-alt

      3. wheelchair

      4. information

      ...

      30. blind-walking

       

      The desired result would be for the artboard list itself to be sorted to read:

       

      1. assistive-listening

      2. assistive-listening-telecoil

      3. blind-walking

      4. braille

      ...

      30. wheelchair-alt

       

      Screenshot 2017-11-15 09.02.45.png

       

      I've scoured the forums for solutions to this. The closest I could find is here: Sort artboards by name, but it doesn't seem to work in Illustrator CC. Also found this (How to sort objects alphabetically (inside of a layer)?), but it is layer-specific, not artboard.

       

      Thanks so much for any help!

        • 1. Re: Script to Sort Artboard List Alphabetically
          OMOTI Level 3

          Hi,

           

          Artboard object probably has no method for sorting.

          Since it does not generate an Artboard object, it may run lightly.

          This try it.

           

          function sortArtboard() {
              var doc = app.activeDocument,
                  properties = [],
                  i,
                  max;
          
              function copyProperties(source) {
                  var props = {},
                      key;
                  for (key in source) {
                      try {
                          props[key] = source[key];
                      } catch (e) {
                      }
                  }
                  return props;
              }
          
              function pasteProperties(source, destination) {
                  var key;
                  for (key in source) {
                      destination[key] = source[key];
                  }
              }
          
              function compareName(a, b) {
                  var comparison = 0;
                  if (a.name > b.name) {
                      comparison = 1;
                  } else if (a.name < b.name) {
                      comparison = -1;
                  }
                  return comparison;
              }
          
              for (i = 0, max = doc.artboards.length; i < max; i += 1) {
                  properties.push(copyProperties(doc.artboards[i]));
              }
          
              properties.sort(compareName);
          
              for (i = 0, max = doc.artboards.length; i < max; i += 1) {
                  pasteProperties(properties[i], doc.artboards[i]);
              }
          
          }
          
          sortArtboard();
          
          • 2. Re: Script to Sort Artboard List Alphabetically
            sensibleworld Level 1

            Awesome! That worked exactly as I needed it to. Thank you so much!

            • 3. Re: Script to Sort Artboard List Alphabetically
              zymox Level 1

              Sorry can you help me? I tried this script but it doesnt work. I'm using Illustrator cc.

              • 4. Re: Script to Sort Artboard List Alphabetically
                OMOTI Level 3

                Did you receive an error message when an error occurred?

                Which is your "Illustrator cc" CC or CC2018?

                It worked with the following versions in my environment. I have not installed CC.

                • Illustrator CS6
                • Illustrator CC 2017
                • Illustrator CC(2018)
                • 5. Re: Script to Sort Artboard List Alphabetically
                  zymox Level 1

                  Thank you! I solved it. Needed to save the script as .js insteD of .jsx. Thank you again.

                   

                  Von meinem iPhone gesendet

                   

                  Am 27.07.2018 um 18:37 schrieb OMOTI <forums_noreply@adobe.com>:

                   

                   

                  Script to Sort Artboard List Alphabetically

                  created by OMOTI in Illustrator Scripting - View the full discussion

                  Did you receive an error message when an error occurred?

                   

                  Which is your "Illustrator cc" CC or CC2018?

                   

                  It worked with the following versions in my environment. I have not installed CC.

                   

                  Illustrator CS6

                  Illustrator CC 2017

                  Illustrator CC(2018)

                  If the reply above answers your question, please take a moment to mark this answer as correct by visiting: https://forums.adobe.com/message/10527623#10527623 and clicking ‘Correct’ below the answer

                  Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page:

                  Please note that the Adobe Forums do not accept email attachments. If you want to embed an image in your message please visit the thread in the forum and click the camera icon: https://forums.adobe.com/message/10527623#10527623

                  To unsubscribe from this thread, please visit the message page at , click "Following" at the top right, & "Stop Following"

                  Start a new discussion in Illustrator Scripting by email or at Adobe Community

                  For more information about maintaining your forum email notifications please go to https://forums.adobe.com/thread/1516624.

                  This email was sent by Adobe Community because you are a registered user.

                  You may unsubscribe instantly from Adobe Community, or adjust email frequency in your email preferences