reverse artboards order

Explorer ,
Feb 20, 2021

Copy link to clipboard

Copied

Hi. 

I found a script online that converts the order of the artboards.
here:

/ reverseArtboardsOrder.jsx
// carlos canto
// http://graphicdesign.stackexchange.com/questions/64865/is-there-a-way-to-automate-reversing-the-order-of-artboards-in-illustrator

function reverseArboardsOrder () {
    var idoc = app.activeDocument;
    var abs = idoc.artboards;
    var abcount = abs.length; 

    var abNames = [];    
    var abRects = [];

    for (i=0; i<abcount; i++) {
        abNames[i] = abs[i].name; 
        abRects[i] = abs[i].artboardRect;
    }

    for (j=0, k=abcount-1; j<abcount; j++, k--) {
        var abRect = abRects[k]; 
        idoc.artboards.remove(k); 
        var newab = idoc.artboards.add(abRect);
        newab.name = abNames[k]; 
    }
    idoc.rearrangeArtboards();
}

reverseArboardsOrder();


The problem is that if there is only one artboard, it gives an error.
I combine such a script in a wider script, so I ask if anything can fix this script for me that if there are one artboards, it will be ignored and will not give an error.

TOPICS
Scripting

Views

41

Likes

Translate

Translate

Report

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

1 Correct Answer

Enthusiast , Feb 20, 2021
femkeblanco Enthusiast , Feb 20, 2021
// reverseArtboardsOrder.jsx // carlos canto // http://graphicdesign.stackexchange.com/questions/64865/is-there-a-way-to-automate-reversing-the-order-of-artboards-in-illustrator function reverseArboardsOrder () { var idoc = app.activeDocument; var abs = idoc.artboards; var abcount = abs.length; if (abs.length > 1) { var abNames = []; var abRects = []; for (i=0; i<abcount; i++) { abNames[i] = abs[i].name; abRects[i] = abs[i].artboardRect; } ...

Likes

Translate

Translate
Jump to answer Jump to answer
Enthusiast ,
Feb 20, 2021

Copy link to clipboard

Copied

// reverseArtboardsOrder.jsx
// carlos canto
// http://graphicdesign.stackexchange.com/questions/64865/is-there-a-way-to-automate-reversing-the-order-of-artboards-in-illustrator

function reverseArboardsOrder () {
    var idoc = app.activeDocument;
    var abs = idoc.artboards;
    var abcount = abs.length; 

if (abs.length > 1) {

    var abNames = [];    
    var abRects = [];

    for (i=0; i<abcount; i++) {
        abNames[i] = abs[i].name; 
        abRects[i] = abs[i].artboardRect;
    }

    for (j=0, k=abcount-1; j<abcount; j++, k--) {
        var abRect = abRects[k]; 
        idoc.artboards.remove(k); 
        var newab = idoc.artboards.add(abRect);
        newab.name = abNames[k]; 
    }
    idoc.rearrangeArtboards();
}

}

reverseArboardsOrder();

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
aviel222 AUTHOR LATEST
Explorer ,
Feb 20, 2021

Copy link to clipboard

Copied

Thanks!!!

Likes

Translate

Translate

Report

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