Showing artboard order

AiScripts
3 min readJan 5, 2022

If the script changes the artboards in an Adobe Illustrator document, how can the user select specific artboards? Display the names of the artboards? But that won’t help in cases of “Artboard 1 copy copy”. JS will detect the artboard via activeDocuments.artboards[index], but when the order on the canvas is chaotic, the indexes in the Artboards panel are not informative.

Artboard position does not correlate with the index

I came up with an idea: when running the script, display the index on each artboard as text, and delete the numbering in the end. I used a similar idea in the MoveArtboards script, where the user enters a range of artboard numbers to move.

All numbers are collected on a new layer
function showAbIndex(name) {
var doc = activeDocument;
var tmpLayer;
try {
tmpLayer = doc.layers.getByName(name);
} catch (e) {
tmpLayer = doc.layers.add();
tmpLayer.name = name;
}
for (var i = 0; i < doc.artboards.length; i++) {
var currAb = doc.artboards[i];
var abWidth = currAb.artboardRect[2] - currAb.artboardRect[0];
var abHeight = currAb.artboardRect[1] - currAb.artboardRect[3];
var label = tmpLayer.textFrames.add();
var labelSize = (abWidth >= abHeight) ? abHeight : abWidth;
label.contents = i + 1;
label.textRange.characterAttributes.size = labelSize / 2;
label.position = [currAb.artboardRect[0], currAb.artboardRect[1]];
}
}

The numbers will be placed in a new layer in the upper left corner of the corresponding artboard. To do this, use try...catch to check if the layer with the name exists. If not, we will create one in the catch block. From the features of the text label:

  • In code the indexing starts with 0, but in life we count with 1, so i + 1;
  • Compare the height and width of the artboard. Then we calculate the font size relative to the larger side.

Don’t forget to delete the temporary layer when the script has finished its main function.

var layerName = 'ARTBOARD_NUMBERS';
showAbIndex(layerName);
// do something..
removeAbIndex(layerName);
function showAbIndex(name) {
var doc = activeDocument;
var tmpLayer;
try {
tmpLayer = doc.layers.getByName(name);
} catch (e) {
tmpLayer = doc.layers.add();
tmpLayer.name = name;
}
for (var i = 0; i < doc.artboards.length; i++) {
var currAb = doc.artboards[i];
var abWidth = currAb.artboardRect[2] - currAb.artboardRect[0];
var abHeight = currAb.artboardRect[1] - currAb.artboardRect[3];
var label = tmpLayer.textFrames.add();
var labelSize = (abWidth >= abHeight) ? abHeight : abWidth;
label.contents = i + 1;
label.textRange.characterAttributes.size = labelSize / 2;
label.position = [currAb.artboardRect[0], currAb.artboardRect[1]];
}
}
function removeAbIndex(name) {
try {
var layerToRm = activeDocument.layers.getByName(name);
layerToRm.remove();
} catch (e) {}
}
Removing numbering in the MoveArtboards script

Let me know if it was helpful to you. You can find me: Facebook / Github / Telegram

--

--

AiScripts

Sergey Osokin. Product Illustrator, Icon Designer, Script Developer (Ai, Ps). Writing about bugs and tricks in Adobe Illustrator scripts