Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Rename psd layers, script?

New Here ,
Jul 24, 2008 Jul 24, 2008
Hello,

Is there an action or/ script available that will rename photoshop layers.?

I have several psd's with about 20 -30 text layers.
The layers generally contain the text information as it's layer name.

I'll need to import this layer comp into After Effects... Unfortunately AE sorts layers based on their naming.. which will then loose their sorting order from Photoshop

Is there a way to add a prefix before each layer name?

something like

001-Text from first layer
002-Text from second layer
003-Text from third layer

etc...

Thanks for any help

Jeff
TOPICS
Actions and scripting
1.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Community Expert ,
Jul 25, 2008 Jul 25, 2008
Im still a Script-beginner myself; I just dont seem to be able to get it right and Layer Sets totally mess it up, but if there are no Layer Sets this could maybe help:

var myDoc = app.activeDocument;
var myNumber = myDoc.layers.length;
for (var i = 0; i < myNumber ; i++) {
var myName = myDoc.layers.name;

if (myNumber - i < 10) {
myDoc.layers.name = "00" + String (myNumber - i ) + "_" + myName;
}

if (myNumber - i >= 10 && i<100) {
myDoc.layers.name = "0" + String (myNumber - i ) + "_" + myName;
}

if (myNumber - i >= 100) {
myDoc.layers.name = String (myNumber - i ) + "_" + myName;
}
}
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jul 25, 2008 Jul 25, 2008
Instead of all of those 'if' statements, just get the right 3 characters of '000' + i

Also, if you move your code into a separate function, you can check the type of layer:

myDoc.layers.typename == 'LayerSet'

then you can pass that layer set back into the function to process the layers inside.

var myDoc = app.activeDocument;
processLayers (myDoc)
function processLayers (objectRef) {
if (objectRef.typename == 'LayerSet') {
processLayers (objectRef)
}
var myNumber = objectRef.layers.length;
for (var i = 0; i < myNumber ; i++) {
var myName = myDoc.layers.name;
//... set myName here
myDoc.layers.name = String (myNumber - i ) + "_" + myName;
}
}
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 25, 2008 Jul 25, 2008
Wow!

Worked great!

Christoph, your script indeed worked with multiple Layer sets.. At least it numbered the all the layers, including the top layer of the layer set.. (those layers within the sets remained unchanged)

Mark, I received an error upon running your script ( with & without Layer sets)

Thanks guys for the help!

Exactly what I'm looking for.

Jeff
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jul 25, 2008 Jul 25, 2008
Sorry, I forgot to switch one of the references to myDoc in the function

var myDoc = app.activeDocument;
processLayers (myDoc)

function processLayers (objectRef) {
var myNumber = objectRef.layers.length;
for (var i = 0; i < myNumber ; i++) {
var myLayer = objectRef.layers;
var myName = myLayer.name;
if (myLayer.typename == 'LayerSet') {
processLayers (myLayer)
}
myLayer.name = (String ("000" + (myNumber - i))).substr(-3) + "_" + myName;
}
}
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 25, 2008 Jul 25, 2008
LATEST
Cool!

Thanks, Mark!

Your latest script works great!

...even renames the layers within the layer set.

I can definately see a use for this.

Thanks again!

Jeff
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines