Skip to main content
Inspiring
May 10, 2022
Answered

Delete all extra artboards

  • May 10, 2022
  • 1 reply
  • 1206 views

Good Morning 🙂

 

We need to delete all extra artboards before saving an AI file and I am having a bit of trouble.  The number of artboards varies so this bit of script I snagged from another post isn't working: https://community.adobe.com/t5/illustrator-discussions/how-to-delete-specific-artboard-in-illustrator-using-script/td-p/8421652

How can I get the JavaScript to create an array that equals the number of Art Boards so this script can work for our needs?


function removeArtboards ( arr ) {
 var i = arr.length; while ( i-- ) activeDocument.artboards[ arr[i] ].remove();
}
removeArtboards( [1,2,3,4,5] );

 

 

Thank you!

This topic has been closed for replies.
Correct answer Charu Rajput

Hi,

Try following version

 

 

function removeArtboards() {
    var doc = app.activeDocument;
    var artboardsLength = doc.artboards.length
    for (var i = artboardsLength - 1; i >= 0; i--) {
        if (app.activeDocument.artboards[i].name != 'Artboard 1') {
            // Use below commented lines if you want to delete the artworks on those artboards.
            /*doc.artboards.setActiveArtboardIndex(i);
            doc.selectObjectsOnActiveArtboard();
            app.cut();*/
            activeDocument.artboards[i].remove();
        }
    }
}
removeArtboards();

 

 

 

Above script will delete all artbaords except with name 'Artboard 1'. If you want to delete the artworks on the artboards as well, uncomment the 3 lines of code in the above script.

 

I hope it helps.

1 reply

Charu Rajput
Community Expert
Community Expert
May 10, 2022

Hi,

Your question, is litlle unclear, when you say extra artboard what does exactly you mean. If you ahve 10 artbaords, then how you identify which you want to delete or not. Please give more information. Anyways, below is the small script that will delete all artboards except one in the active document. It will only delete the artboard not any content on those artboards.

function removeArtboards() {
    var artboardsLength = app.activeDocument.artboards.length
    var i = artboardsLength;
    while (i>1){
        activeDocument.artboards[i-1].remove();
        i--;
    }
}
removeArtboards();
Best regards
Inspiring
May 10, 2022

Hello Charu Rajput,

The only Artboard we want to keep is the original - Artboard #1.  All others need to be deleted.  There could be 3 there could be 53 artboards, it all depends on the project.

 

Hope that helps clarify things 🙂

 

 

Charu Rajput
Community Expert
Charu RajputCommunity ExpertCorrect answer
Community Expert
May 10, 2022

Hi,

Try following version

 

 

function removeArtboards() {
    var doc = app.activeDocument;
    var artboardsLength = doc.artboards.length
    for (var i = artboardsLength - 1; i >= 0; i--) {
        if (app.activeDocument.artboards[i].name != 'Artboard 1') {
            // Use below commented lines if you want to delete the artworks on those artboards.
            /*doc.artboards.setActiveArtboardIndex(i);
            doc.selectObjectsOnActiveArtboard();
            app.cut();*/
            activeDocument.artboards[i].remove();
        }
    }
}
removeArtboards();

 

 

 

Above script will delete all artbaords except with name 'Artboard 1'. If you want to delete the artworks on the artboards as well, uncomment the 3 lines of code in the above script.

 

I hope it helps.

Best regards