Skip to main content
Participant
February 14, 2023
Answered

Need plugin / custom script for renaming artboards with numbering suffixes

  • February 14, 2023
  • 4 replies
  • 4560 views

Hello Everyone,

I basically need to rename artboards in bulk to save time...just mostly adding numbers as suffixes to artboards.For instance,

 

With the attached example, the resulting artboard names would be:
1- Layer 1_Gk01
2- Layer 2_Gk02
3- Layer 3_Gk03

 

I need to rename the selected artboard with consecutive numbering suffixes from the previous artboard (not always starting from _10). I am not sure if this is possible. So I am seeking the help of photoshop wizrads here to find a fix😅. Thanks in advance.

 

 

This topic has been closed for replies.
Correct answer Stephen Marsh

@V0ID_GUY 

 

The following script isn’t perfect, however, it is the best that I can do for now.

 

Perhaps a better script writer than me can fix the code as it also indiscriminately processes layer groups and frames (as these are all layerSets)... The isArtboard function that I hacked works when used on a single layer outside of a for loop, but doesn't work when used in a for loop?

 

Edit: 23rd Februray 2023: Code updated, it should now only rename top-level artboards, not groups or frames.

 

/*
Rename artboards with custom prefix and sequential numbers.jsx
v1.1 - 23rd February 2023, Stephen Marsh
*/

var sequencePartTwo = activeDocument.activeLayer.name.replace(/(^.+)(_\D+)(0*)(\d+)/, "$2");
var sequenceSuffixLength = 2;
var sequencePartFour = activeDocument.activeLayer.name.replace(/(^.+)(_\D+)(0*)(\d+)/, "$4");
// Backward loop - bottom to top
// for (var i = activeDocument.layerSets.length - 1; i >= 0; i--) {
// Forward loop - top to bottom
for (var i = 0; i < activeDocument.layers.length; i++) {
    try {
        activeDocument.activeLayer = activeDocument.layers[i];
        if (activeDocument.activeLayer.typename === "LayerSet" && isArtboard() === true) {
            var sequencePartOne = activeDocument.layers[i].name.replace(/(^.+)(_\D+)(0*)(\d+)/, "$1");
            activeDocument.layers[i].name = sequencePartOne + sequencePartTwo + sequenceSuffix(sequencePartFour, sequenceSuffixLength);
            sequencePartFour++;
        }
    } catch (e) {
        alert("Error!" + "\r" + e + ' ' + e.line);
    }
}


///// Functions /////

function sequenceSuffix(num, digit) {
    var tmp = num.toString();
    while (tmp.length < digit) {
        tmp = "0" + tmp;
    }
    return tmp;
}

function isArtboard() {
    // modified from a script by greless with hints from jazz-y!
    // returns true or false
    try {
        var d = new ActionDescriptor();
        var r = new ActionReference();
        r.putEnumerated(stringIDToTypeID('layer'), stringIDToTypeID('ordinal'), stringIDToTypeID('targetEnum'));
        var options = executeActionGet(r);
        return options.hasKey(stringIDToTypeID('artboard')); // test for the required key
    } catch (e) {
        //alert(e);
    }
}

 

4 replies

Todd_Morgan
Legend
June 8, 2023
Greg von Neulich
Known Participant
May 3, 2023

we made a Photoshop plug-in that can do this. The unlimited version is 12$. 

 

Full Version (12$):
https://exchange.adobe.com/apps/cc/c36e02fb/swift


Trial Version (Limited to 5 Actions):
https://exchange.adobe.com/apps/cc/412c1dcd/swift-trial-version

 

Its also a big help with getting the layers selected to rename them.

Stephen Marsh
Community Expert
Stephen MarshCommunity ExpertCorrect answer
Community Expert
February 15, 2023

@V0ID_GUY 

 

The following script isn’t perfect, however, it is the best that I can do for now.

 

Perhaps a better script writer than me can fix the code as it also indiscriminately processes layer groups and frames (as these are all layerSets)... The isArtboard function that I hacked works when used on a single layer outside of a for loop, but doesn't work when used in a for loop?

 

Edit: 23rd Februray 2023: Code updated, it should now only rename top-level artboards, not groups or frames.

 

/*
Rename artboards with custom prefix and sequential numbers.jsx
v1.1 - 23rd February 2023, Stephen Marsh
*/

var sequencePartTwo = activeDocument.activeLayer.name.replace(/(^.+)(_\D+)(0*)(\d+)/, "$2");
var sequenceSuffixLength = 2;
var sequencePartFour = activeDocument.activeLayer.name.replace(/(^.+)(_\D+)(0*)(\d+)/, "$4");
// Backward loop - bottom to top
// for (var i = activeDocument.layerSets.length - 1; i >= 0; i--) {
// Forward loop - top to bottom
for (var i = 0; i < activeDocument.layers.length; i++) {
    try {
        activeDocument.activeLayer = activeDocument.layers[i];
        if (activeDocument.activeLayer.typename === "LayerSet" && isArtboard() === true) {
            var sequencePartOne = activeDocument.layers[i].name.replace(/(^.+)(_\D+)(0*)(\d+)/, "$1");
            activeDocument.layers[i].name = sequencePartOne + sequencePartTwo + sequenceSuffix(sequencePartFour, sequenceSuffixLength);
            sequencePartFour++;
        }
    } catch (e) {
        alert("Error!" + "\r" + e + ' ' + e.line);
    }
}


///// Functions /////

function sequenceSuffix(num, digit) {
    var tmp = num.toString();
    while (tmp.length < digit) {
        tmp = "0" + tmp;
    }
    return tmp;
}

function isArtboard() {
    // modified from a script by greless with hints from jazz-y!
    // returns true or false
    try {
        var d = new ActionDescriptor();
        var r = new ActionReference();
        r.putEnumerated(stringIDToTypeID('layer'), stringIDToTypeID('ordinal'), stringIDToTypeID('targetEnum'));
        var options = executeActionGet(r);
        return options.hasKey(stringIDToTypeID('artboard')); // test for the required key
    } catch (e) {
        //alert(e);
    }
}

 

V0ID_GUYAuthor
Participant
February 15, 2023

Thank you so much😍...tested it...works goood...gonna save much of your time.

Stephen Marsh
Community Expert
Community Expert
February 15, 2023

You're welcome! As long as you don't have any top-level layer groups or frames which are not contained in artboards, you should be OK.

Stephen Marsh
Community Expert
Community Expert
February 14, 2023

Presuming that the layers have the correct digits in them to "borrow" for the numbering... The quickest way is to leverage an existing script, without having to create a custom script.

 

 

https://github.com/Paul-Riggott/PS-Scripts/blob/master/Layer%20Name%20Edit.jsx

 

I changed line 20 from:

 

 

var myBrush = g.newBrush(g.BrushType.SOLID_COLOR, [0.99, 0.99, 0.99, 1]);

 

 

To:

 

 

var myBrush = g.newBrush(g.BrushType.SOLID_COLOR, [0.2, 0.2, 0.2, 1]);

 

 

For a dark interface.

 

The regular expression find/replace can be hard-coded into the script so that you don't have to type it in each time.

 

Find:

(Layer )(\d+)

 

Replace:

Layer $2_Gk0$2

 

You would need to manually account for including/excluding the leading zero padding character.

V0ID_GUYAuthor
Participant
February 14, 2023

I appreciate your instant response, however I am a complete noob to Photoshop scripts. I was unable to grasp what you were attempting to say. Could you please assist me in detail.

Stephen Marsh
Community Expert
Community Expert
February 14, 2023