Batch rename layers/layer comps with auto numbering

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

saj
Posts: 1
Joined: Wed Mar 15, 2017 11:45 pm

Batch rename layers/layer comps with auto numbering

Post by saj »

Hey,

I have over a hundred layers that I need to batch rename, for example layer1, layer2, layer3 to pg1, pg2, pg3. I also need to do the same thing with the layer comps.

Has anyone done this sort of script already?

Thanks
Saj
Revnart
Posts: 9
Joined: Wed Sep 28, 2016 8:56 am

Re: Batch rename layers/layer comps with auto numbering

Post by Revnart »

maybe script wrote by Kamil Khadeyev will help you.
http://blog.darkwark.com/layerRenamer/
blastframe
Posts: 3
Joined: Wed Feb 20, 2019 12:50 am

Re: Batch rename layers/layer comps with auto numbering

Post by blastframe »

Here is my script for renaming layer comps

Code: Select all

#target photoshop

function renameLayerComps()
{
var activeDoc = app.activeDocument;
comps = activeDoc.layerComps;

function pad(n, width, z)
{
z = z || '0';
n = n + '';
return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n;
}

var dialog = "dialog { \
text: 'Batch Rename Layer Comps', \
destination: Panel { \
alignment: 'left', \
alignChildren:['left','top'], \
orientation: 'row', \
text: 'Layer Comp Name Prefix', \
input: EditText { text: 'Layer_Comp_', preferredSize: [230,20] }, \
}, \
rename: Group { \
alignment: 'right', \
orientation: 'row', \
zeroPad: Checkbox { text: 'Pad with leading zero (e.g. 01, 02, etc.)', value: false }, \
}, \
buttons: Group { \
alignment: 'left', \
orientation: 'row', \
rename: Button { text: 'Rename', properties:{ name: 'ok' } }, \
cancel: Button { text: 'Cancel' }, \
} \ }";

dlg = new Window( dialog );

dlg.buttons.rename.onClick = function() {
prefix=dlg.destination.input.text;
zeroPad=dlg.rename.zeroPad.value;
rename(prefix,zeroPad);
dlg.close();
}

dlg.buttons.cancel.onClick = function() {
dlg.close();
}

dlg.show();

function rename(prefix, zeroPad)
{
for (var i=0;i<comps.length;i++)
{
indexNumber = i+1;
if (i<10 && zeroPad)
{
indexNumber = pad(i+1, 2);
}
comps[i].name = prefix + indexNumber;
}
}
}

renameLayerComps();