Skip to main content
Inspiring
July 16, 2022
Answered

Photoshop layer groups with incremental numbers

  • July 16, 2022
  • 2 replies
  • 891 views

The Photoshop action creates the CC 01 layer group with the Curves 1 and the Hue Saturation  1 adjustment layers inside the CC 01 layer group. 

 

Typically, it is necessary to add multiple CC 01 layer groups to edit the Photoshop file. 

To stay organized, it would be useful to automatically increment the CC 01 layer group number by 1 every time the action runs. 

 

What is the simplest way to achieve this with a script?

I’m thinking the script should follow these steps and repeat steps with adjustment layers

 

Crete variable CCcnt

Assign value CCcnt = “CC 01”

 

Check if CC 01 layer group exists

If false

Run action to make CC 01 layer grp

Exit script

 

If true

Run action to make CC 01 layer grp

Rename CC 01 to CC 02 with the script 

Get the last two characters of the layer group  name

Increment the last character by 1

Get the new layer name CC 02

Assing to CC 02 variable CCcnt

Exit script

This topic has been closed for replies.
Correct answer Polycontrast

Thank you very much, the script works great!

I had to do a minor adjustment. Recreate the action with the folder name CC 00 and change the variable in the script to CC 00.  Without this change, the script creates the folder CC 02. With the change, it creates the folder CC 01.

Your help is greatly appreciated Chuck!

2 replies

Chuck Uebele
Community Expert
Community Expert
July 17, 2022

Ok, so try inserting this script into your action after you make a new layer group, but befor you add any other layers. You want the layer group that you want to add to the next number selected.

 

#target photoshop
var doc = activeDocument;
var curLay =doc.activeLayer;
var layPar = curLay.parent;
var numA = new Array()

for(var i=0;i<layPar.layers.length;i++){
    if(layPar.layers[i].typename == 'LayerSet'){
        if(!isNaN (Number(layPar.layers[i].name.substr (3, 2)))){
            numA.push([Number(layPar.layers[i].name.substr (3, 2)),i])
            }     
        }
    }
numA.sort();
numA.reverse();
if(numA.length ==0){curLay.name = 'CC 01'}
else{
    var nextNum = 101 + numA[0][0]
    curLay.name = 'CC ' + nextNum.toString().substr (1, 2)
    }

 

PolycontrastAuthorCorrect answer
Inspiring
July 17, 2022

Thank you very much, the script works great!

I had to do a minor adjustment. Recreate the action with the folder name CC 00 and change the variable in the script to CC 00.  Without this change, the script creates the folder CC 02. With the change, it creates the folder CC 01.

Your help is greatly appreciated Chuck!

Chuck Uebele
Community Expert
Community Expert
July 17, 2022

Glad it's working. Odd, I thought it did create the CC 01 group.

Chuck Uebele
Community Expert
Community Expert
July 17, 2022

Which action are you talking about? One that you created? Are these layer groups at the top level, meaning that they're not inside another group?

Inspiring
July 17, 2022

Yes, I created the Photoshop acion to make the CC 01 layer group.

The action runs at the top level in the layer palette and sometimes in subfolders.