Copy link to clipboard
Copied
Good Morning,
I have a script I wrote that uses Radio Buttons to select which function to use. It works as intended however when the "Extra Artboards" button is selected there is an Error that Pops up and I don't know why.
Thank you for your time!!
var choice
var w = new Window("dialog");
var g = w.add("group");
var a = g.add("radiobutton", undefined, "Main Artboard");
var b = g.add("radiobutton", undefined, "Extra Artboards");
var button = w.add("button", undefined, "OK");
var radiobuttons = [a, b];
for (var i = 0; i < radiobuttons.length; i++) {
(function (i) {
radiobuttons[i].onClick = function () {
choice = radiobuttons[i].text;
};
})(i);
}
w.show();
var removeArtboards;
if (choice == "Main Artboard") {
// Main
function removeArtboards ( arr ) {
var i = arr.length; while ( i-- ) activeDocument.artboards[ arr[i] ].remove();
}
removeArtboards( [0] );
} else if (choice == "Extra Artboards") {
// Extra
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') {
activeDocument.artboards[i].remove();
}
}
}
removeArtboards();
}
it errors when it tries to remove the last artboard.
change the below line to ">" instead of ">="
for (var i = artboardsLength - 1; i >= 0; i--)
Copy link to clipboard
Copied
it errors when it tries to remove the last artboard.
change the below line to ">" instead of ">="
for (var i = artboardsLength - 1; i >= 0; i--)
Copy link to clipboard
Copied
That did the trick! Thank you!
Copy link to clipboard
Copied
you probably don't need this line after the fix above, since the last artboard name could be anything ie "Artboard 2"
if (app.activeDocument.artboards[i].name != 'Artboard 1') {