Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Delete all extra artboards

Engaged ,
May 10, 2022 May 10, 2022

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-illustrato...

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!

TOPICS
Scripting
1.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , May 10, 2022 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();*/
            ac
...
Translate
Adobe
Community Expert ,
May 10, 2022 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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
May 10, 2022 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 🙂

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 10, 2022 May 10, 2022
LATEST

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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines