Copy link to clipboard
Copied
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!
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
...
Copy link to clipboard
Copied
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();
Copy link to clipboard
Copied
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 🙂
Copy link to clipboard
Copied
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.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now