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
@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
...
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!");
}
}
https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html#Photoshop
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.
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()");
Copy link to clipboard
Copied
Absolute legend, thanks a lot!
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.
Copy link to clipboard
Copied
No, this is perfect. Much appreciated, Stephen