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

Sequentially number layer sets

Community Beginner ,
May 13, 2012 May 13, 2012

Great, apparently if I add Tags it wipes out my question and just posts the tags as the message body. Brilliant. Re-typing...

I have a large and growing PSD with many layer sets (folders of layers.) I need to sequentially number the layer sets, but preserve their existing names. For example, layer set named "foo" should be renamed "001 foo",  the next layer set "bar" should be renamed "002 bar" and so on.

Doing this manually would take a long time, but more importantly, as I add new layer sets and reorder them I don't want to have to do it all over again.

I am not a programmer so I don't know where to begin writing this script. Google helped me find a few scripts that do something similar, but not exactly what I want. Most of the scripts I found will rename layers, but I need to rename the layer sets (folders.)

If it helps, I'll explain what I'm ultimately trying to do. I want to export each of my layer sets to an image, and have those images numbered sequentially based on the order of the layer sets. I already found a script that will export all of my layer sets to JPG images, so if I can find the script described above, I should be able to do this in two steps (1. rename layer sets, 2. export images.) If there is an easier or better approach, let me know.

I have Photoshop CS5 on Mac OSX Lion.

Any help is appreciated! Thanks!

TOPICS
Actions and scripting
1.5K
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 ,
May 17, 2012 May 17, 2012

What order should the numbers go (should 001 be the uppemost or lowermost LayerSet) and how about LayerSets in LayerSets (or are they all top level)?

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 Expert ,
May 17, 2012 May 17, 2012

You could give this a try:

// add sequential three places number to beginning of layersets’ names or change existing three places number;

// 2012, use at your own risk;

#target photoshop

if (app.documents.length > 0) {

var myDocument = app.activeDocument;

var theSets = collectLayerSets(myDocument);

for (var m = 0; m < theSets.length; m++) {

          var thisSet = theSets;

          var myRegExp = /^\d{3}/;

          if (thisSet.name.match(myRegExp) == null) {thisSet.name = bufferNumberWithZeros(m + 1, 3) + " " + thisSet.name}

          else {thisSet.name = thisSet.name.replace(myRegExp, bufferNumberWithZeros(m + 1, 3))}

          }

};

////// function collect all layersets //////

function collectLayerSets (theParent) {

          if (!allLayerSets) {var allLayerSets = new Array}

          else {};

          for (var m = theParent.layers.length - 1; m >= 0;m--) {

                    var theLayer = theParent.layers;

// apply the function to layersets;

                    if (theLayer.typename == "LayerSet") {

                              allLayerSets = allLayerSets.concat(collectLayerSets(theLayer))

                              allLayerSets = allLayerSets.concat(theLayer);

                              }

                    }

          return allLayerSets

          };

////// buffer number with zeros //////

function bufferNumberWithZeros (number, places) {

          var theNumberString = String(number);

          for (var o = 0; o < (places - String(number).length); o++) {

                    theNumberString = String("0" + theNumberString)

                    };

          return theNumberString

          };

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 ,
May 18, 2012 May 18, 2012

Thanks, c.pfaffenbichler!

This works perfectly. Though I was thinking 001 would be at the top (the uppermost layer set.)

Still, I can work with this by reversing the order my layers in the panel.

For my purposes, I'm not concerned with layer sets inside of layers set. I just need the first level of layer sets renamed.

I really appreciate it!!!

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 Expert ,
May 19, 2012 May 19, 2012
LATEST

Could you try this?

// add sequential three places number to beginning of layersets’ names or change existing three places number;

// 2012, use at your own risk;

#target photoshop

if (app.documents.length > 0) {

var myDocument = app.activeDocument;

var theSets = collectLayerSets(myDocument);

for (var m = 0; m < theSets.length; m++) {

          var thisSet = theSets;

          var myRegExp = /^\d{3}/;

          var theNumber = theSets.length - m;

          if (thisSet.name.match(myRegExp) == null) {thisSet.name = bufferNumberWithZeros(theNumber, 3) + " " + thisSet.name}

          else {thisSet.name = thisSet.name.replace(myRegExp, bufferNumberWithZeros(theNumber, 3))}

          }

};

////// function collect all layersets //////

function collectLayerSets (theParent) {

          if (!allLayerSets) {var allLayerSets = new Array}

          else {};

          for (var m = theParent.layers.length - 1; m >= 0;m--) {

                    var theLayer = theParent.layers;

// apply the function to layersets;

                    if (theLayer.typename == "LayerSet") {

                              allLayerSets = allLayerSets.concat(collectLayerSets(theLayer))

                              allLayerSets = allLayerSets.concat(theLayer);

                              }

                    }

          return allLayerSets

          };

////// buffer number with zeros //////

function bufferNumberWithZeros (number, places) {

          var theNumberString = String(number);

          for (var o = 0; o < (places - String(number).length); o++) {

                    theNumberString = String("0" + theNumberString)

                    };

          return theNumberString

          };

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