Highlighted

Sort artboards by name

Explorer ,
Feb 07, 2012

Copy link to clipboard

Copied

We have over 50 artboards in most of our documents.  Is there a way to sort the artboards as listed in the artboards panel by name via script?

Adobe Community Professional
Correct answer by CarlosCanto | Adobe Community Professional

do you still need it? here's a script, it only works with numbers for now, it needs more work if there are alpha characters in the artboard names.

#target illustrator

// script.name = sortArtboardsNumericallyCS5only.jsx;

// script.description = reArranges the Artboards indexes (for now works with Numbers only)

// script.required = an open document with at least 2 artboards, CS5 only;

// script.parent = CarlosCanto; // 2/21/12;

// script.elegant = false;

var idoc = app.activeDocument;

var abs = idoc.artboards;

var abcount = abs.length; // save the artboard count

var absNames = []; // array to hold artboards names

for (i=0; i<abcount; i++) {

    absNames = abs.name; // get all artboard names in an array

}

absNames.sort(function (a,b) { return a-b }); // sort Numerically

// duplicate all artboards, in order according to the sorted array

for (j=0; j<abcount; j++) {

                        var newAB = idoc.artboards.add(abs.getByName(absNames).artboardRect); // duplicate AB, which one? go by the sorted array

            newAB.name = absNames; // rename artboard

}

// delete original set of artboards

for (k=abcount-1; k>=0; k--) {

        idoc.artboards.remove(k);

}

TOPICS
Scripting

Views

3.5K

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Sort artboards by name

Explorer ,
Feb 07, 2012

Copy link to clipboard

Copied

We have over 50 artboards in most of our documents.  Is there a way to sort the artboards as listed in the artboards panel by name via script?

Adobe Community Professional
Correct answer by CarlosCanto | Adobe Community Professional

do you still need it? here's a script, it only works with numbers for now, it needs more work if there are alpha characters in the artboard names.

#target illustrator

// script.name = sortArtboardsNumericallyCS5only.jsx;

// script.description = reArranges the Artboards indexes (for now works with Numbers only)

// script.required = an open document with at least 2 artboards, CS5 only;

// script.parent = CarlosCanto; // 2/21/12;

// script.elegant = false;

var idoc = app.activeDocument;

var abs = idoc.artboards;

var abcount = abs.length; // save the artboard count

var absNames = []; // array to hold artboards names

for (i=0; i<abcount; i++) {

    absNames = abs.name; // get all artboard names in an array

}

absNames.sort(function (a,b) { return a-b }); // sort Numerically

// duplicate all artboards, in order according to the sorted array

for (j=0; j<abcount; j++) {

                        var newAB = idoc.artboards.add(abs.getByName(absNames).artboardRect); // duplicate AB, which one? go by the sorted array

            newAB.name = absNames; // rename artboard

}

// delete original set of artboards

for (k=abcount-1; k>=0; k--) {

        idoc.artboards.remove(k);

}

TOPICS
Scripting

Views

3.5K

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Feb 07, 2012 1
Explorer ,
Feb 09, 2012

Copy link to clipboard

Copied

Anyone have any ideas on this?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 09, 2012 0
Guru ,
Feb 09, 2012

Copy link to clipboard

Copied

I don't think that there are any methods for doing this…

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 09, 2012 0
Explorer ,
Feb 09, 2012

Copy link to clipboard

Copied

No way with actions, javascript, vb or any other means to automate this task? Holding out hope if anyone has any ideas J

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 09, 2012 0
Guru ,
Feb 09, 2012

Copy link to clipboard

Copied

Tim, artboards are pretty new the to AI the fact that script has access to any of this is nothing short of of a miracle… There are some things that have been about much longer and still no access… With artboards you can add() Remove() and Insert() plus get/set the active one… You can also rearrange but this is the actual location in terms of the document NOT the order positioning in the GUI palette.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 09, 2012 0
Adobe Community Professional ,
Feb 21, 2012

Copy link to clipboard

Copied

do you still need it? here's a script, it only works with numbers for now, it needs more work if there are alpha characters in the artboard names.

#target illustrator

// script.name = sortArtboardsNumericallyCS5only.jsx;

// script.description = reArranges the Artboards indexes (for now works with Numbers only)

// script.required = an open document with at least 2 artboards, CS5 only;

// script.parent = CarlosCanto; // 2/21/12;

// script.elegant = false;

var idoc = app.activeDocument;

var abs = idoc.artboards;

var abcount = abs.length; // save the artboard count

var absNames = []; // array to hold artboards names

for (i=0; i<abcount; i++) {

    absNames = abs.name; // get all artboard names in an array

}

absNames.sort(function (a,b) { return a-b }); // sort Numerically

// duplicate all artboards, in order according to the sorted array

for (j=0; j<abcount; j++) {

                        var newAB = idoc.artboards.add(abs.getByName(absNames).artboardRect); // duplicate AB, which one? go by the sorted array

            newAB.name = absNames; // rename artboard

}

// delete original set of artboards

for (k=abcount-1; k>=0; k--) {

        idoc.artboards.remove(k);

}

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 21, 2012 0
Explorer ,
Feb 22, 2012

Copy link to clipboard

Copied

What a lifesaver! This is great…all of my artboards are named by numbers, so it’s absolutely perfect for our use.

Thanks so much!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 22, 2012 0
Explorer ,
Mar 12, 2012

Copy link to clipboard

Copied

I just ran into the 100 artboard limit, when I have a document with 51 or more artboards.  Because the script duplicates every artboard, it puts me over 100 temporarily and causes the script to fail.  I don't see a way around this at the moment, do you?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 12, 2012 0
Adobe Community Professional ,
Mar 12, 2012

Copy link to clipboard

Copied

good point...let me think about it

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 12, 2012 0
Guru ,
Mar 12, 2012

Copy link to clipboard

Copied

Does this do it…?

#target illustrator

function sortArtboards() {

 

          if ( app.documents.length == 0 ) { return; }

          var i, obj, doc, count, list;

 

          doc = app.activeDocument;

 

          count = doc.artboards.length; // Original length

 

          doc.artboards.insert( doc.visibleBounds, count ); // At end

 

          app.redraw();

 

          list = Array();

 

          // All but the new one…

          for ( i = count-1; i >= 0; i-- ) {

 

                    obj = Object();

                    obj.abname = doc.artboards.name;

                    obj.abrect = doc.artboards.artboardRect;

                    //obj.abindex = i;

                    list.push( obj );

 

                    doc.artboards.remove( i );

 

          };

          list.sort( function ( a, b ) { return a.abname - b.abname } );

          //$.writeln( list.toSource() );

 

          for ( i = 0; i < count; i++ ) {

 

                    doc.artboards.insert( list.abrect, i );

                    doc.artboards.name = list.abname

 

          };

          doc.artboards[count].remove();

 

};

sortArtboards();

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 12, 2012 2
Explorer ,
Mar 14, 2012

Copy link to clipboard

Copied

Works perfectly.  Thanks so much for the help!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 14, 2012 0
Guru ,
Mar 15, 2012

Copy link to clipboard

Copied

Tim my guess was that this is just for PDF page order? You can however add this…

doc.rearrangeArtboards( DocumentArtboardLayout.GridByRow, 3, 144, true );

And it moves the artboards about in the doc too…

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 15, 2012 0
Explorer ,
Mar 15, 2012

Copy link to clipboard

Copied

We’re very systematic. It was actually just so we can go to the same place on all of our hundreds of master files and get to the same product. Our artboards are all different sizes, and there are about 50ish of them, so this addition didn’t work. It said the re-arrangement would put artboards outside of the canvas range. Thanks again so much for your help, as always.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 15, 2012 0
Guru ,
Mar 15, 2012

Copy link to clipboard

Copied

Yeah… I've seen one of your 50 artboard files… And doubted it would work there… It was of interest to me and my experiments on a test file though… may prove usefull to others to know…

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 15, 2012 0
Community Beginner ,
Nov 03, 2017

Copy link to clipboard

Copied

Hi,

Just refreshing the thread. This script would be very useful for arranging Artboards by name!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 03, 2017 0
Explorer ,
Aug 02, 2020

Copy link to clipboard

Copied

This script works for me.

 

#target illustrator

var doc = app.activeDocument;
var artboards = doc.artboards;
var artboard_count = artboards.length; // save the artboard count
var artboard_names = []; // array to hold artboards names

for (i=0; i<artboard_count; i++)
{
    artboard_names.push(artboards[i].name);
}

artboard_names.sort();

for (j=0; j<artboard_count; j++)
{ 
    var aname = artboard_names[j];
    var rect = artboards.getByName(aname).artboardRect;
    var newAB = artboards.add(rect); // duplicate AB, which one? go by the sorted array
    newAB.name = artboard_names[j]; // rename artboard
}

// delete original set of artboards
for (k=artboard_count-1; k>=0; k--)
{
    artboards.remove(k);
}

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 02, 2020 1