Skip to main content
Participant
October 26, 2022
Answered

Automatically change Artboard name to Artboard dimensions in pixels

  • October 26, 2022
  • 2 replies
  • 1321 views

I have to change the name of my artboard to the file dimensions all the time so I would love it if anyone knew of a script I could use to make this happen every time.

 

Thanks a lot 

Correct answer Stephen Marsh

@James268064665dsv – You can also try this script, which will change all artboard names in a single run (a single history step undo is included).

 

/*
Rename All Artboards to Artboard Dimensions.jsx
https://community.adobe.com/t5/photoshop-ecosystem-discussions/automatically-change-artboard-name-to-artboard-dimensions-in-pixels/m-p/13299226
Stephen Marsh, v1.0 - 27th October 2022
*/

#target photoshop

function main() {

    app.activeDocument.activeLayer = app.activeDocument.layerSets[app.activeDocument.layerSets.length - 1];

    // Loop forward over top level layer sets
    // for (var i = 0; i < app.activeDocument.layerSets.length; i++) {
    // Loop backward over top level layer sets
    for (var i = app.activeDocument.layerSets.length - 1; i >= 0; i--) {
        try {

            app.activeDocument.activeLayer = app.activeDocument.layerSets[i];

            var originalRulerUnits = app.preferences.rulerUnits;
            app.preferences.rulerUnits = Units.PIXELS;

            // Active Artboard Dimensions, by Rune L-H
            var ref = new ActionReference();
            ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
            var artBoardRect = executeActionGet(ref).getObjectValue(stringIDToTypeID("artboard")).getObjectValue(stringIDToTypeID("artboardRect"));
            var artBoardRectWidth = new UnitValue(artBoardRect.getDouble(stringIDToTypeID("right")) - artBoardRect.getDouble(stringIDToTypeID("left")), "px");
            var artBoardRectHeight = new UnitValue(artBoardRect.getDouble(stringIDToTypeID("bottom")) - artBoardRect.getDouble(stringIDToTypeID("top")), "px");

            activeDocument.activeLayer.name = artBoardRectWidth.value + " x " + artBoardRectHeight.value;

            app.preferences.rulerUnits = originalRulerUnits;

        } catch (e) {}
    }
}
app.activeDocument.suspendHistory("Rename All Artboards to Artboard Dimensions", "main()");

2 replies

Stephen Marsh
Community Expert
Stephen MarshCommunity ExpertCorrect answer
Community Expert
October 27, 2022

@James268064665dsv – You can also try this script, which will change all artboard names in a single run (a single history step undo is included).

 

/*
Rename All Artboards to Artboard Dimensions.jsx
https://community.adobe.com/t5/photoshop-ecosystem-discussions/automatically-change-artboard-name-to-artboard-dimensions-in-pixels/m-p/13299226
Stephen Marsh, v1.0 - 27th October 2022
*/

#target photoshop

function main() {

    app.activeDocument.activeLayer = app.activeDocument.layerSets[app.activeDocument.layerSets.length - 1];

    // Loop forward over top level layer sets
    // for (var i = 0; i < app.activeDocument.layerSets.length; i++) {
    // Loop backward over top level layer sets
    for (var i = app.activeDocument.layerSets.length - 1; i >= 0; i--) {
        try {

            app.activeDocument.activeLayer = app.activeDocument.layerSets[i];

            var originalRulerUnits = app.preferences.rulerUnits;
            app.preferences.rulerUnits = Units.PIXELS;

            // Active Artboard Dimensions, by Rune L-H
            var ref = new ActionReference();
            ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
            var artBoardRect = executeActionGet(ref).getObjectValue(stringIDToTypeID("artboard")).getObjectValue(stringIDToTypeID("artboardRect"));
            var artBoardRectWidth = new UnitValue(artBoardRect.getDouble(stringIDToTypeID("right")) - artBoardRect.getDouble(stringIDToTypeID("left")), "px");
            var artBoardRectHeight = new UnitValue(artBoardRect.getDouble(stringIDToTypeID("bottom")) - artBoardRect.getDouble(stringIDToTypeID("top")), "px");

            activeDocument.activeLayer.name = artBoardRectWidth.value + " x " + artBoardRectHeight.value;

            app.preferences.rulerUnits = originalRulerUnits;

        } catch (e) {}
    }
}
app.activeDocument.suspendHistory("Rename All Artboards to Artboard Dimensions", "main()");
Participant
October 27, 2022

Absolute legend, thanks a lot! 

Stephen Marsh
Community Expert
Community Expert
October 27, 2022

You're welcome, I was hoping that the all artboards version would do, although I can make another version just for multiple selected artboards if it is really needed.

Stephen Marsh
Community Expert
Community Expert
October 26, 2022

@James268064665dsv – What do you mean by "file dimensions"? To clarify your request - do you want to change the selected artboard name to the artboard dimensions in px (not document canvas dimensions)?

 

Is this only for the selected artboard, or for multiple artboards?

 

@James268064665dsv – You can try the following script for a selected artboard:

 

/*
Rename Artboard to Artboard Dimensions.jsx
https://community.adobe.com/t5/photoshop-ecosystem-discussions/automatically-change-artboard-name-to-artboard-dimensions-in-pixels/m-p/13299226
Stephen Marsh, v1.0 - 27th October 2022
*/

#target photoshop

var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;

var doc = activeDocument;
var aLayer = doc.activeLayer
var ab = artboard_rectangle(aLayer);
var abW = ab[2] - ab[0];
var abH = ab[3] - ab[1];

activeDocument.activeLayer.name = abW + ' x ' + abH;

app.preferences.rulerUnits = originalRulerUnits;


function artboard_rectangle(layer) {
/*
https://community.adobe.com/t5/photoshop-ecosystem-discussions/photoshop-scripting-artboard-size-values/td-p/13255332
by Chuck Uebele
*/
    try {
        var r = new ActionReference();
        r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("artboard"));
        if (layer) r.putIdentifier(stringIDToTypeID("layer"), layer.id);
        else r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
        var d = executeActionGet(r).getObjectValue(stringIDToTypeID("artboard")).getObjectValue(stringIDToTypeID("artboardRect"));
        var bounds = new Array();
        bounds[0] = d.getUnitDoubleValue(stringIDToTypeID("left"));
        bounds[1] = d.getUnitDoubleValue(stringIDToTypeID("top"));
        bounds[2] = d.getUnitDoubleValue(stringIDToTypeID("right"));
        bounds[3] = d.getUnitDoubleValue(stringIDToTypeID("bottom"));
        return bounds;
    } catch (e) {
        alert("An artboard must be selected!");
    }
}

 

  1. Copy the code text to the clipboard
  2. Open a new blank file in a plain-text editor (not in a word processor)
  3. Paste the code in
  4. Save the text file as .txt
  5. Rename the file extension from .txt to .jsx
  6. Install or browse to the .jsx file to run (see below)

https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html#Photoshop

 

Participant
October 27, 2022

Thanks so much for the quick reply! 

This seems to work great. Is it possible to be able to select multiple artboards at once and run the script? At the moment it only works on one artboard when I have 3 selected.