Skip navigation
benjudy47
Currently Being Moderated

Sequentially number layer sets

May 13, 2012 4:17 AM

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!

 
Replies
  • Currently Being Moderated
    May 17, 2012 2:11 AM   in reply to benjudy47

    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)?

     
    |
    Mark as:
  • Currently Being Moderated
    May 17, 2012 2:52 AM   in reply to benjudy47

    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[m];

              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[m];

    // 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

              };

     
    |
    Mark as:
  • Currently Being Moderated
    May 19, 2012 12:38 AM   in reply to benjudy47

    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[m];

              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[m];

    // 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

              };

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points