Copy link to clipboard
Copied
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
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(
...
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!
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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)
}
Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
Glad it's working. Odd, I thought it did create the CC 01 group.
Copy link to clipboard
Copied
I am not sure why initially the script created the folder CC 02 in my system.
It could be related to the action structure. The original action had the make group step at the end of the action after the adjustment layers. When I moved the make group step to the beginning of the action it create the CC 002 group. The workaround was to edit the action to make the group CC 00 and change the variable to CC 00 in the script.