Rename layer sets to add numbers sequentially

Discussion of Photoshop Scripting, Photoshop Actions and Photoshop Automation in General

Moderators: Tom, Kukurykus

benjudy

Rename layer sets to add numbers sequentially

Post by benjudy »

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 very long time, as I have over 100 layer sets and counting in this one file. Also, I will have similarly structured PSD files in the future. More importantly, as I add new layer sets and reorder them I don't want to have to do it all over again. So it would be great if the script could also re-number layer sets, if they are already numbered.

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!

Professional AI Audio Generation within Adobe Premiere Pro - Download Free Plugin here

txuku

Rename layer sets to add numbers sequentially

Post by txuku »

Bonjour benjudy

Not sure I fully understand - I am French - try this code :

Code: Select all//RenommeGroupes.jsx

nb = 1;
j=10;
Zero = "00";
calcScan();
 
function calcScan(  )
{
  var docRef = app.activeDocument;
  var calqueGroup;
  for (i = 0; i < docRef.layers.length; i++)
  {
    calqueGroup = docRef.layers;
    if ( calqueGroup.typename ==  "LayerSet" )
    {
      var calcGName;
      var calcGName = calqueGroup.name; 
      testNombre(calcGName);
      testZero();
      calqueGroup.name = Zero + nb + calcGName1;
      nb = nb + 1;
    }
  }
}

function testZero()
{
  if(nb==j)
    {
      Zero = Zero.substr(1);
      j=j*10;
    }



function testNombre(calcGName)
{
  var testNb = new Array( parseInt(calcGName.slice( 0, 1 )), parseInt(calcGName.slice( 0, 2 )), parseInt(calcGName.slice( 0, 3 )) ) ;

  if(isNaN(testNb[0])==false)
  {
      calcGName = calcGName.substr(1);
      if(isNaN(testNb[1])==false)
      {
        calcGName = calcGName.substr(1);
        if(isNaN(testNb[2])==false)
        {
            calcGName = calcGName.substr(1);
        }
      }
  }
  calcGName1 = calcGName
  return ( calcGName1 )               
benjudy

Rename layer sets to add numbers sequentially

Post by benjudy »

txuku: Thank you! Merci beaucoup!

Your script does exactly what I need.
txuku

Rename layer sets to add numbers sequentially

Post by txuku »