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

Automatically change Artboard name to Artboard dimensions in pixels

Community Beginner ,
Oct 26, 2022 Oct 26, 2022

Copy link to clipboard

Copied

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 

TOPICS
macOS

Views

793

Translate

Translate

Report

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 , Oct 27, 2022 Oct 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.activ
...

Votes

Translate

Translate
Adobe
Community Expert ,
Oct 26, 2022 Oct 26, 2022

Copy link to clipboard

Copied

@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

 

Votes

Translate

Translate

Report

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 Beginner ,
Oct 27, 2022 Oct 27, 2022

Copy link to clipboard

Copied

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. 

Votes

Translate

Translate

Report

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 ,
Oct 27, 2022 Oct 27, 2022

Copy link to clipboard

Copied

@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()");

Votes

Translate

Translate

Report

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 Beginner ,
Oct 27, 2022 Oct 27, 2022

Copy link to clipboard

Copied

Absolute legend, thanks a lot! 

Votes

Translate

Translate

Report

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 ,
Oct 27, 2022 Oct 27, 2022

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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 Beginner ,
Oct 27, 2022 Oct 27, 2022

Copy link to clipboard

Copied

LATEST

No, this is perfect. Much appreciated, Stephen

Votes

Translate

Translate

Report

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