Copy link to clipboard
Copied
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.
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.
/*
...
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Info on saving and running scripts here:
https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html
Copy link to clipboard
Copied
But I dont want to always have the same number in artboard name.....will give you an example
If I select the top artboard (here the one with "_GK01" at the end) and run the script, it must automatically rename the below artboards as:
1. Image_GK01
2. File_GK02
3. Folder_GK03
So I am expecting a script to take the last part of the slected artboard name & rename below artboards by adding consecutive numbers to it....Hope this helps.
Copy link to clipboard
Copied
OK, as mentioned the previous find/replace method relied of the layers having the correct numbers.
You have mentioned renaming/numbering in bulk. You have also mentioned selected artboards, however, one screenshot had no artboards selected and the other only 1 of 3 selected... So, is this only for selected artboards, or for all artboards in the doc?
Is the expectation to only run the script once and all artboards are then renamed/sequentially numbered? Or would you need to run this multiple times in the documents life? If multiple times, would all layers simply be renamed/renumbered again, or do you need only new artboards renamed that don't match the current numbering and therefore require the numbers to start where the previous one finished?
Copy link to clipboard
Copied
I mean that based on the selected artboards final numbering part ( _0GK1), all other artboards under the selected one in the document must be numbered sequentially/consecutively ( _0GK2, _0GK3,......so on)
I think that my last post explains my requirements a bit clear than the first one...So I am expecting a single script that would work on every document (ran once per document)...I would do the renaming of the first artboard myself...the script must just start renaming consecutively after mine.
Copy link to clipboard
Copied
Thanks, I think that I can (mostly) meet these requirements.
Copy link to clipboard
Copied
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);
}
}
Copy link to clipboard
Copied
Thank you so much😍...tested it...works goood...gonna save much of your time.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
I have overcome the issue with differentiating between the 3 different kinds of layerSets, so now only artboards are renamed, not groups or frames.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
This worked like a charm!!!! https://exchange.adobe.com/apps/cc/096e3394?pluginId=096e3394 LayerRename+ | Adobe Exchange
Find more inspiration, events, and resources on the new Adobe Community
Explore Now