Copy link to clipboard
Copied
Greetings.
I'm looking for a way to automate file naming according to layer group name.
I have a PSD file with several layer groups in it. The task is to export several JPG versions of this PSD file, with each version including a specific layer group content only. And each JPG must be named accordingly to it's layer group.
For example:
The PSD name is 2020.01.01 Artist (US Tour).psd.
It contains three layer groups named:
2020.01.02 Artist (New York)
2020.01.03 Artist (Boston)
2020.01.04 Artist (Philadelphia)
I need every layer group to be exported as JPG, and these JPG files must be automatically named after their layer groups.
Is there a script that can automate this process?
Thanks a lot.
{Thread renamed by moderator}
Okay, this script will export all the top level groups, into the same folder, and use the group name as the file name. It will leave the visibility on of any layer not in one of the groups.
#target photoshop
var jpgOptions = new JPEGSaveOptions();
jpgOptions.quality = 8;
var doc = activeDocument;
var dPath = doc.path
var gArray = new Array();
for(var i=0;i<doc.layers.length;i++){
doc.activeLayer = doc.layers[i];
if(doc.layers[i].typename == 'LayerSet'){
gArray.push(doc.layers[i]
...
Copy link to clipboard
Copied
Hi There,
Welcome to the Adobe Community!
As you're looking to automate file naming according to layer group name, please have a look at a similar discussion here and see if it helps: Export Groups to Files?
You may also have a look at this and let us know how it goes: Exporting Groups (Folders) to Files in Photoshop
Regards,
Sahil
Copy link to clipboard
Copied
You linked us to a thread started in 2009? How that is possible if new forum stores topics no older than from after 2016. Is it because later replies to that thread were posted in in February of 2019? So I mean if not the fact of refreshing topic after 10 years that one would be lost (like others old-current users reported, or just archived, but where if I may know it)?
Copy link to clipboard
Copied
Copy link to clipboard
Copied
For each group, are all the layers that you need exported visible, or do they need to be turned on for exporting with the group?
Also, are all the groups that you want to export on the top level - not in another layerset?
Copy link to clipboard
Copied
All the layers within every group are visible. And all the groups are on the top level.
Copy link to clipboard
Copied
Do you have a background layer that has to be visible and exported with all the groups?
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Okay, this script will export all the top level groups, into the same folder, and use the group name as the file name. It will leave the visibility on of any layer not in one of the groups.
#target photoshop
var jpgOptions = new JPEGSaveOptions();
jpgOptions.quality = 8;
var doc = activeDocument;
var dPath = doc.path
var gArray = new Array();
for(var i=0;i<doc.layers.length;i++){
doc.activeLayer = doc.layers[i];
if(doc.layers[i].typename == 'LayerSet'){
gArray.push(doc.layers[i]);
doc.layers[i].visible = false;
}
}
for(var i=0;i<gArray.length;i++){
gArray[i].visible = true;
var gName = gArray[i].name;
$.writeln(gName)
doc.saveAs (new File(dPath +'/' + gName + '.jpg'), jpgOptions,true);
gArray[i].visible = false;
};
for(var i=0;i<gArray.length;i++){
gArray[i].visible = true;
};
Copy link to clipboard
Copied
That was quick! Your script works and it's amazing, thanks a lot!
Is there a chance to upgrade it a bit? There's a background layer group with poster art and 3 layer groups with text info and logos. How can we automate the export of JPG posters keeping the background layer group the same but applying different layer groups with show info? As a result I need to have 3 different JPGs exported (one per each city), and every of them must have the same background.
I attached a PSD file so you can test it. Thanks a lot again!
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Okay, this script will exclude changing the group Backgroug Group. Just keep that name the same in all your files!
#target photoshop
var jpgOptions = new JPEGSaveOptions();
jpgOptions.quality = 8;
var doc = activeDocument;
var dPath = doc.path
var gArray = new Array();
for(var i=0;i<doc.layers.length;i++){
doc.activeLayer = doc.layers[i];
if(doc.layers[i].typename == 'LayerSet' && doc.layers[i].name.toLowerCase() != 'background group'){
gArray.push(doc.layers[i]);
doc.layers[i].visible = false;
}
}
for(var i=0;i<gArray.length;i++){
gArray[i].visible = true;
var gName = gArray[i].name;
$.writeln(gName)
doc.saveAs (new File(dPath +'/' + gName + '.jpg'), jpgOptions,true);
gArray[i].visible = false;
};
for(var i=0;i<gArray.length;i++){
gArray[i].visible = true;
};
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Are you on Win or Mac?
Copy link to clipboard
Copied
Copy link to clipboard
Copied
If you're on Win, this is the path to get to the download folder. Currently the dPath just gets the path for the current file. The "`" will point to the current users folder.
var dPath = new Folder('~/Downloads/');
Copy link to clipboard
Copied
I'm not sure where the download folder is on the Mac, but the "`" should still point to the user's folder.
Copy link to clipboard
Copied
I have not tested, however that looks right Chuck as ('~/Desktop/‘) works and both folders are in the users home folder. So it should all come down to permissions.
EDIT: Yes it works!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now