I checked in the Photoshop's Documentation if there was any option to work with artboards in scripting.

Unfortunately I couldn't find anything. Does anyone have experience in working with artboards through scripting?

I'd like to generate artboard's names based on differents format and size.

For instance:


Is there any option to do that?


To my knowledge artboards unfortunately aren't available in DOM. However we know that photoshop artboards are basically fancy groups (and groups are basically fancy layers) with more settings, and their settings are available through AM. Here's an example script that'll rename all artboards to doc name + artboard dimensions:

var doc = activeDocument,
    layers = doc.layers; //getting top layers because artboards are top layers

for (var i = 0, l = layers.length; i < l; i++)
    doc.activeLayer = layers[i];
    if (isArtBoard()) //checking if artboard because there could be a group or a normal layer on a top level
        var abSize = getArtboardDimensions();
        doc.activeLayer.name = doc.name + "-" + abSize[0] + "x" + abSize[1]

function isArtBoard()
    var ref = new ActionReference();
    ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
    return executeActionGet(ref).getBoolean(stringIDToTypeID("artboardEnabled"));
}; // end of isArtBoard()

function getArtboardDimensions()
    var ref = new ActionReference();
    ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
    var desc = executeActionGet(ref).getObjectValue(stringIDToTypeID("artboard")).getObjectValue(stringIDToTypeID("artboardRect"));
    var w = desc.getDouble(stringIDToTypeID("right")) - desc.getDouble(stringIDToTypeID("left"));
    var h = desc.getDouble(stringIDToTypeID("bottom")) - desc.getDouble(stringIDToTypeID("top"));
    return [w, h]
}; // end of getArtboardDimensions()


enter image description here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.