2 Replies Latest reply on Nov 18, 2017 2:21 PM by sensibleworld

    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 2

          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!