• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
2

Export Groups to Files?

New Here ,
Sep 06, 2009 Sep 06, 2009

Copy link to clipboard

Copied

Is there a way to export multiple GROUPS into individual files, such as jpg?  If I run the File > Scripts > Export LAYERS To Files, each LAYER becomes a jpeg, but i'd like each GROUP to be flattened and exported as a jpg. Is there a script or funtion that performs this task?

TOPICS
Actions and scripting

Views

118.9K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 2 Correct answers

Community Expert , Sep 08, 2009 Sep 08, 2009

You could try attached Script, You’d have to adapt it to jpg, currently it saves pdfs.

I have not tested it very extensively and only in CS4 though.

// creates pdf-copies of layersets with dialog to select layers and suffix;
// be advised: existing files of identical names will be overwritten without warnings;
// 2009, pfaffenbichler, use it at your own risk;
#target photoshop
if (app.documents.length > 0) {
////////////////////////////////////
// get document-path and -title;
	var myDocument = 
...

Votes

Translate

Translate
Community Expert , Sep 09, 2009 Sep 09, 2009

You could replace the pdfOptions with

var jpgopts = new JPEGSaveOptions();

jpgopts.embedColorProfile = true;

jpgopts.formatOptions = FormatOptions.STANDARDBASELINE;

jpgopts.matte = MatteType.NONE;

jpgopts.quality = 10;

and edit that according to Your needs.

Then replace »pdfOpts« and ».pdf« in the saveAs-line with »jpgopts« and ».jpg«.

Votes

Translate

Translate
Adobe
New Here ,
Apr 29, 2015 Apr 29, 2015

Copy link to clipboard

Copied

I am running an older version of Paul's script and I'm getting a crash on Photoshop CC 64-bit, no error is thrown, program just shuts down.  Seems to work on the 32-bit version though.  Also, the links to the newer version of this script are empty, is there anywhere I can get the most updated version of this?

Thanks in advance!

-Kris

EDIT:  Link is working for me now and I downloaded the latest version of "Layer Saver".  Still crashes CC 64-bit, and CC 32-bit seems to not finish the task when started.

Anyone get this working in Photoshop CC 32 or 64 bit?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 05, 2016 Jan 05, 2016

Copy link to clipboard

Copied

Hope you found the answer to this already but I'll answer anyway, for future reference:
it really helped me to find out that in photoshop cc you can save groups as simply as by selecting the ones you want,right clicking the mouse and selecting the "export as..." option. It saved me around 30 min per project!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 15, 2016 Mar 15, 2016

Copy link to clipboard

Copied

Yeah but what if you have like 50 layer groups and you want to save each group as a separate file?  Your suggested method is great for exporting one or two but so much in a batch scenario. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 30, 2016 Apr 30, 2016

Copy link to clipboard

Copied

Same, i need to save like 30 layers and it takes lot of time selecting each layer from groups

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 01, 2016 May 01, 2016

Copy link to clipboard

Copied

If you can clarify the scenario (Layer and Group structure etc.) you could ask for help over at

Photoshop Scripting

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 12, 2009 Sep 12, 2009

Copy link to clipboard

Copied

Thanks for this, it works really well. I've tried making 2 changes to the script but it doesn't seem to work right

 

  • Use ExportOptionsSaveForWeb with JPEG 80% but it's giving me just 1 bad quality file name "filename-#0.jpg" with the contents of the lowest group
  • Have the script elaborate only the top level groups to reduce the time it takes to load up and show the dialog box. At the moment it's picking up every group in the file.

 

What is wrong in this code?

// creates pdf-copies of layersets with dialog to select layers and suffix;
// be advised: existing files of identical names will be overwritten without warnings;
// 2009, pfaffenbichler, use it at your own risk;
//#target photoshop
if (app.documents.length > 0) {
////////////////////////////////////
// get document-path and -title;
	var myDocument = app.activeDocument;
	var myDocName = myDocument.name.match(/(.*)\.[^\.]+$/)[1];
	var myPath = myDocument.path;
	var theLayerSets = collectLayerSets(myDocument);
////// filter for checking if entry is numeric, thanks to xbytor //////
	numberKeystrokeFilter = function() {
	this.text = this.text.replace(",", "");
	this.text = this.text.replace(".", "");
	if (this.text.match(/[^\-\.\d]/)) {
		this.text = this.text.replace(/[^\-\.\d]/g, "");
		};
	if (this.text == "") {
		this.text = "0"
		}
	};
////////////////////////////////////
// create the dialog;	
	var dlg = new Window('dialog', "pdfs from layersets", [500,300,930,840]);	
//create list for layer-selection;
	dlg.layerRange = dlg.add('panel', [21,20,279,445], "select layersets to create pdfs of");
	dlg.layerRange.layersList = dlg.layerRange.add('listbox', [11,20,240,405], '', {multiselect: true});
	for (var q = 0; q < theLayerSets.length; q++) {
		dlg.layerRange.layersList.add ("item", theLayerSets[q].name);
		dlg.layerRange.layersList.items[q].selected = true
		};
// entry for suffix;
	dlg.suffix = dlg.add('panel', [290,20,410,85], "enter suffix");
	dlg.suffix.suffixText = dlg.suffix.add('edittext', [11,20,99,40], "", {multiline:false});
// entry for number;
	dlg.number = dlg.add('panel', [290,100,410,165], "start with #");
	dlg.number.startNumber = dlg.number.add('edittext', [11,20,45,40], "1", {multiline:false});
	dlg.number.addNumber = dlg.number.add('checkbox', [55,20,105,40], "add", {multiline:false});
	dlg.number.startNumber.onChange = numberKeystrokeFilter;
// field to add layer-name;
	dlg.layerName = dlg.add('panel', [290,180,410,270], "layer-name");
	dlg.layerName.doAddName = dlg.layerName.add('radiobutton', [11,20,120,40], "add it");
	dlg.layerName.dontAddName = dlg.layerName.add('radiobutton', [11,45,120,65], "don’t add it");
	dlg.layerName.doAddName.value = true;
// field to select target-folder;
	dlg.target = dlg.add('panel', [290,285,410,445], "target-folder");
	dlg.target.targetSel = dlg.target.add('button', [11,20,100,40], "select");
	dlg.target.targetField = dlg.target.add('statictext', [11,50,100,155], String(myPath), {multiline:true});
	dlg.target.targetSel.onClick = function () {
		var target = Folder.selectDialog("select a target folder");
		dlg.target.targetField.text = target.fsName
		};
// ok- and cancel-buttons;
	dlg.buildBtn = dlg.add('button', [220,460,410,475], 'OK', {name:'ok'});
	dlg.cancelBtn = dlg.add('button', [21,460,210,475], 'Cancel', {name:'cancel'});
	dlg.warning = dlg.add('statictext', [21,490,410,530], "be advised: existing files of the same name will be replaced without prompting", {multiline: true});
	dlg.center();
////////////////////////////////////
	var myReturn = dlg.show ();
// in case of OK;
	if (myReturn == true && dlg.layerRange.layersList.selection.length > 0) {
// get the number instead of the name;	
		var theLayerSelection = new Array;
		var theColl = dlg.layerRange.layersList.items;
		for (var p = 0; p < dlg.layerRange.layersList.items.length; p++) {
			if (dlg.layerRange.layersList.items[p].selected == true) {
				theLayerSelection = theLayerSelection.concat(p);
				}
			};
// collect the rest of the variables,
		var theSuffix = dlg.suffix.suffixText.text;
		var theNumber = Number (dlg.number.startNumber.text) - 1;
		var theLayerNameAdd = dlg.layerName.doAddName.value;
		var theDestination = dlg.target.targetField.text;
		var theNumbering = dlg.number.addNumber.value;
// pdf options
		var jpgopts = new ExportOptionsSaveForWeb();
		jpgopts.format = SaveDocumentType.JPEG;
		jpgopts.includeProfile = true;
		jpgopts.quality = 80;













// create the pdf-name;
		if (theSuffix.length > 0) {
			var aSuffix = "_" + theSuffix
			}
		else {
			var aSuffix = ""
			};
// create a flattened copy;
		var theCopy = myDocument.duplicate("thecopy", true);
// do the operation;
		for (var m = theLayerSelection.length - 1; m >= 0; m--) {
			app.activeDocument = myDocument;
			var theLayer = theLayerSets[theLayerSelection[m]];
			if (theNumbering == true) {
				theNumber = bufferNumberWithZeros((Number (theNumber) + 1), 2);
				theNumberString =  "_" + theNumber
				};
			else {
				theNumberString = ""
				};
// get the layername for the pdf-name;
			if (theLayerNameAdd == true) {
				var aLayerName = "_" + theLayer.name.replace("/", "_")
				}
			else {
				var aLayerName = ""
				}			
// transfer layerset over to the copy;
			theLayer.duplicate (theCopy, ElementPlacement.PLACEATBEGINNING);
			app.activeDocument = theCopy;
// hide the llast added layer;
			theCopy.layers[1].visible = false;
			theCopy.exportDocument(new File(theDestination+"/"+myDocName+aSuffix+aLayerName+theNumberString+".jpg"), ExportType.SAVEFORWEB, jpgopts );
			};
		theCopy.close(SaveOptions.DONOTSAVECHANGES);
		}
	};
else {alert ("no document open")};
////////////////////////////////////
////// 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
	};
////// 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 == "ArtLayer") {
		//	allLayerSets = allLayerSets.concat(theLayer)
			}
		else {
// this line includes the layer groups;
			allLayerSets = allLayerSets.concat(theLayer);
			allLayerSets = allLayerSets.concat(collectLayerSets(theLayer))
			}
		}
	return allLayerSets
};

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Sep 13, 2009 Sep 13, 2009

Copy link to clipboard

Copied

mazmax wrote:

  • Use ExportOptionsSaveForWeb with JPEG 80% but it's giving me just 1 file name "filename-#0.jpg" with the contents of the lowest group

I have seen others report this filename issue when scripting SFW on MacOS. I think the fix is to go into make sure your Filename Compatibility is set to Unix in the Saving Files section of the Output Settings in the flyout menu of the SFW dialog.

Another option is to let SFW do it's thing and have the script rename the file to the desired name after the export.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 14, 2009 Sep 14, 2009

Copy link to clipboard

Copied

Yep you're right Mike!

I added jpgopts.byteOrder = ByteOrder.MACOS; and it works fine

Thanks!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 02, 2011 Feb 02, 2011

Copy link to clipboard

Copied

Great scripts.

I have no idea how Photoshop scripts work, but i would be very happe if someone could tweak the script so it only selects the root groups and esports if for jpgs.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 19, 2011 May 19, 2011

Copy link to clipboard

Copied

Or if someone can have one that saves it as PSD... trimmed... can someone hook me up with that script? I'll send you some Paypal beer donation. Thanks in advance!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
May 19, 2011 May 19, 2011

Copy link to clipboard

Copied

This should now save as a PSD ...

#target photoshop
function main(){
if(!documents.length) return;
var doc = activeDocument;
var oldPath = activeDocument.path;
for(var a=0;a<doc.layerSets.length;a++){
activeDocument.activeLayer = activeDocument.layers.getByName(doc.layerSets.name);
dupLayers();
activeDocument.mergeVisibleLayers();
activeDocument.trim(TrimType.TRANSPARENT,true...
.name +".psd");
SavePSD(saveFile);
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
    }
}
main()...
















Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 19, 2011 May 19, 2011

Copy link to clipboard

Copied

Hey thanks for the quick reply. However I am getting an error message and I am not getting prompted with the dialogue box to choose which ones I want to extract ...

here is the error message

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 19, 2011 May 19, 2011

Copy link to clipboard

Copied

Screen shot 2011-05-19 at 6.00.55 PM.jpg

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
May 19, 2011 May 19, 2011

Copy link to clipboard

Copied

This script isn't written for selected layersets, it does them all.

If you want to save selected layers/layersets this script might do the job as it support layers and layerset and persistant Top/Background layers.


#target photoshop
function main(){
var LSets = activeDocument.layerSets.length;
var ArtLayers = activeDocument.artLayers.length;
var NoOfLayers = activeDocument.layers.length;
var Back = hasBackground();
var hasTop = false;
var selLayers =getSelectedLayersIdx();
var selGroups=[];
if(LSets>0){
    for(var s in selLayers){
   if(isLayerSet(selLayers)) selGroups.push(selLayers);
        }
    }
if(activeDocument.layers[0].typename == 'ArtLayer') hasTop = true;
var win = new Window('dialog','Layer Saver');
g = win.graphics;
var myBrush = g.newBrush(g.BrushType.SOLID_COLOR, [0.99, 0.99, 0.99, 1]);
g.backgroundColor = myBrush;

win.p1= win.add("panel", undefined, undefined, {borderStyle:"black"});
win.p1.preferredSize=[500,20];
win.g1 = win.p1.add('group');
win.g1.orientation = "row";
win.title = win.g1.add('statictext',undefined,'Layer Saver');
win.title.alignment="fill";
var g = win.title.graphics;
g.font = ScriptUI.newFont("Georgia","BOLDITALIC",22);
win.g5 =win.p1.add('group');
win.g5.orientation = "column";
win.g5.alignChildren='left';
win.g5.spacing=0;
if(LSets == 0){
win.g5.rb1 = win.g5.add('radiobutton',undefined,'Save selected layers');
win.g5.rb2 = win.g5.add('radiobutton',undefined,'Save selected layers along with the top layer');
win.g5.rb3 = win.g5.add('radiobutton',undefined,'Save selected layers along with background layer');
win.g5.rb4 = win.g5.add('radiobutton',undefined,'Save all layers');
win.g5.rb5 = win.g5.add('radiobutton',undefined,'Save all layers along with the top layer');
win.g5.rb6 = win.g5.add('radiobutton',undefined,'Save all layers along with background layer');
win.g5.rb3.enabled=Back;
win.g5.rb6.enabled=Back;
win.g5.rb4.value=true;
}else{
win.g5.rb1 = win.g5.add('radiobutton',undefined,'Save selected layerSets');
win.g5.rb2 = win.g5.add('radiobutton',undefined,'Save selected layerSets along with the top layer');
win.g5.rb3 = win.g5.add('radiobutton',undefined,'Save selected layerSets along with background layer');
win.g5.rb4 = win.g5.add('radiobutton',undefined,'Save all layerSets');
win.g5.rb5 = win.g5.add('radiobutton',undefined,'Save all layerSets along with the top layer');
win.g5.rb6 = win.g5.add('radiobutton',undefined,'Save all layerSets along with background layer');
win.g5.rb3.enabled=Back;
win.g5.rb6.enabled=Back;
win.g5.rb2.enabled=hasTop;
win.g5.rb5.enabled=hasTop;
if(selGroups.length <1){
    win.g5.rb1.enabled=false;
    win.g5.rb2.enabled=false;
    win.g5.rb3.enabled=false;
    }
win.g5.rb4.value=true;
    }
win.p2 = win.add("panel", undefined, undefined, {borderStyle:"black"});
win.p2.preferredSize=[500,20];
win.p2.st1 = win.p2.add('statictext',undefined,'Output details');
win.p2.st1.graphics.font = ScriptUI.newFont("Tahoma", "Bold", 18);
win.g10 =win.p2.add('group');
win.g10.orientation = "row";
win.g10.alignment='left';
win.g10.et1 = win.g10.add('edittext');
win.g10.et1.preferredSize=[350,20];
win.g10.bu1 = win.g10.add('button',undefined,'Select Folder');
win.g10.bu1.onClick=function(){
var Folder1 = Folder(app.activeDocument.path);
outputFolder = Folder.selectDialog("Please select the output folder",Folder1);
if(outputFolder !=null){
  win.g10.et1.text =  decodeURI(outputFolder.fsName);
  }
}
win.g12 =win.p2.add('group');
win.g12.orientation = "row";
win.g12.alignment='left';
win.g12.cb1 = win.g12.add('checkbox',undefined,'Merge Visible Layers?');
win.g12.cb2 = win.g12.add('checkbox',undefined,'Trim Layer');

win.g15 =win.p2.add('group');
win.g15.orientation = "row";
win.g15.alignment='left';
var Options= ["Layer/Group Name","FileName + Sequence No.","FileName + Layer/Group Name ","User Defined with Sequence No."];
win.g15.st1 = win.g15.add('statictext',undefined,'Save Options..');
win.g15.dd1 = win.g15.add('dropdownlist',undefined,Options);
win.g15.dd1.selection=0;
win.g15.et1 = win.g15.add('edittext');
win.g15.et1.preferredSize=[150,20];
win.g15.et1.hide();
win.g15.dd1.onChange=function(){
  if(this.selection.index==3){
      win.g15.et1.show();
      }else{
          win.g15.et1.hide();
          }
    }
win.g18 =win.p2.add('group');
win.g18.orientation = "row";
win.g18.st1 = win.g18.add('statictext',undefined,'Save as :');
var Types = ["PNG","PSD","PDF","TIF","JPG"];
win.g18.dd1 = win.g18.add('dropdownlist',undefined,Types);
win.g18.dd1.selection = 0;
win.g18.alignment='left';
win.g20 =win.p2.add('group');
win.g20.orientation = "row";
win.g20.bu1 = win.g20.add('button',undefined,'Process');
win.g20.bu1.preferredSize=[200,35];
win.g20.bu2 = win.g20.add('button',undefined,'Cancel');
win.g20.bu2.preferredSize=[200,35];
win.g20.bu1.onClick=function(){
    if(win.g10.et1.text == ''){
        alert("No Output Folder has been Selected!");
        return;
        }
    if(win.g15.dd1.selection.index==3){
        if(win.g15.et1.text ==''){
            alert("No FileName Has Been Entered!");
            return;
            }
        }
    win.close(1);
Process();
}
win.center();
win.show();
function Process(){
if(LSets == 0){
//Process layers only
if(win.g5.rb1.value){//Save selected layers
for(var b in selLayers){
    selectLayerByIndex(Number(selLayers));
     var lName = activeDocument.activeLayer.name;
    var saveFile= File(outputFolder+ "/" + getName(b,lName));
    dupLayers();
    if(win.g12.cb1.value){
        try{activeDocument.mergeVisibleLayers();}catch(e){}
        }
     if(win.g12.cb2.value){
         try{activeDocument.trim(TrimType.TRANSPARENT,true,true,true,true);}catch(e){}
         }
    SaveDOC(saveFile);
    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
    }
    }//End Save selected layers
if(win.g5.rb2.value){//Save selected layers along with the top layer
for(var b in selLayers){
    selectLayerByIndex(Number(selLayers));
     var lName = activeDocument.activeLayer.name;
    activeDocument.activeLayer= activeDocument.layers[0];
    selectLayerByIndex(Number(selLayers),true);
    var saveFile= File(outputFolder+ "/" + getName(b,lName));
    dupLayers();
    if(win.g12.cb1.value){
        try{activeDocument.mergeVisibleLayers();}catch(e){}
        }
    if(win.g12.cb2.value){
         try{activeDocument.trim(TrimType.TRANSPARENT,true,true,true,true);}catch(e){}
         }
    SaveDOC(saveFile);
    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
    }
    }//End Save selected layers along with the top layer
if(win.g5.rb3.value){//Save selected layers along with background layer
    for(var b in selLayers){
    selectLayerByIndex(Number(selLayers));
     var lName = activeDocument.activeLayer.name;
    activeDocument.activeLayer = activeDocument.layers[activeDocument.layers.length-1];
    selectLayerByIndex(Number(selLayers),true);
    var saveFile= File(outputFolder+ "/" + getName(b,lName));
    dupLayers();
        if(win.g12.cb1.value){
        try{activeDocument.mergeVisibleLayers();}catch(e){}
        }
    if(win.g12.cb2.value){
         try{activeDocument.trim(TrimType.TRANSPARENT,true,true,true,true);}catch(e){}
         }
    SaveDOC(saveFile);
    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
    }
    }//End Save selected layers along with background layer
if(win.g5.rb4.value){//Save all layers
selectAllLayers();
selLayers =getSelectedLayersIdx();
for(var b in selLayers){
     selectLayerByIndex(Number(selLayers));
     var lName = activeDocument.activeLayer.name;
    var saveFile= File(outputFolder+ "/" + getName(b,lName));
    dupLayers();
        if(win.g12.cb1.value){
        try{activeDocument.mergeVisibleLayers();}catch(e){}
        }
    if(win.g12.cb2.value){
         try{activeDocument.trim(TrimType.TRANSPARENT,true,true,true,true);}catch(e){}
         }
    SaveDOC(saveFile);
    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
     }
    }//End Save all layers
if(win.g5.rb5.value){//Save all layers along with the top layer
selectAllLayers(1);
selLayers =getSelectedLayersIdx();
for(var b in selLayers){
    selectLayerByIndex(Number(selLayers));
     var lName = activeDocument.activeLayer.name;
    activeDocument.activeLayer = activeDocument.layers[0];
    selectLayerByIndex(Number(selLayers),true);
    var saveFile= File(outputFolder+ "/" + getName(b,lName));
    dupLayers();
        if(win.g12.cb1.value){
        try{activeDocument.mergeVisibleLayers();}catch(e){}
        }
    if(win.g12.cb2.value){
         try{activeDocument.trim(TrimType.TRANSPARENT,true,true,true,true);}catch(e){}
         }
    SaveDOC(saveFile);
    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
    }
    }//End Save all layers along with the top layer
if(win.g5.rb6.value){//Save all layers along with background layer
selectAllLayers();
selLayers =getSelectedLayersIdx();
    for(var b in selLayers){
    selectLayerByIndex(Number(selLayers));
     var lName = activeDocument.activeLayer.name;
    activeDocument.activeLayer = activeDocument.layers[activeDocument.layers.length-1];
    selectLayerByIndex(Number(selLayers),true);
    var saveFile= File(outputFolder+ "/" + getName(b,lName));
    dupLayers();
        if(win.g12.cb1.value){
        try{activeDocument.mergeVisibleLayers();}catch(e){}
        }
    if(win.g12.cb2.value){
         try{activeDocument.trim(TrimType.TRANSPARENT,true,true,true,true);}catch(e){}
         }
    SaveDOC(saveFile);
    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
    }
    }//End Save all layers along with background layer
    }else{
//Process LayerSets Only
if(win.g5.rb1.value){//Save selected layerSets
    for(var g in selGroups){
        selectLayerByIndex(Number(selGroups));
        var lName = activeDocument.activeLayer.name;
        var saveFile= File(outputFolder+ "/" + getName(g,lName));
        dupLayers();
            if(win.g12.cb1.value){
        try{activeDocument.mergeVisibleLayers();}catch(e){}
        }
    if(win.g12.cb2.value){
         try{activeDocument.trim(TrimType.TRANSPARENT,true,true,true,true);}catch(e){}
         }
    SaveDOC(saveFile);
    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
        }
   }//End Save selected layerSets
if(win.g5.rb2.value){//Save selected layerSets along with the top layer
    for(var g in selGroups){
        selectLayerByIndex(Number(selGroups));
     var lName = activeDocument.activeLayer.name;
    activeDocument.activeLayer= activeDocument.layers[0];
    selectLayerByIndex(Number(selGroups),true);
    var saveFile= File(outputFolder+ "/" + getName(g,lName));
    dupLayers();
        if(win.g12.cb1.value){
        try{activeDocument.mergeVisibleLayers();}catch(e){}
        }
    if(win.g12.cb2.value){
         try{activeDocument.trim(TrimType.TRANSPARENT,true,true,true,true);}catch(e){}
         }
    SaveDOC(saveFile);
    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
        }
    }//End Save selected layerSets along with the top layer
if(win.g5.rb3.value){//Save selected layerSets along with background layer
    for(var g in selGroups){
    selectLayerByIndex(Number(selGroups));
     var lName = activeDocument.activeLayer.name;
    activeDocument.activeLayer = activeDocument.layers[activeDocument.layers.length-1];
    selectLayerByIndex(Number(selGroups),true);
    var saveFile= File(outputFolder+ "/" + getName(g,lName));
    dupLayers();
        if(win.g12.cb1.value){
        try{activeDocument.mergeVisibleLayers();}catch(e){}
        }
    if(win.g12.cb2.value){
         try{activeDocument.trim(TrimType.TRANSPARENT,true,true,true,true);}catch(e){}
         }
    SaveDOC(saveFile);
    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
    }
    }//End Save selected layerSets along with background layer
if(win.g5.rb4.value){//Save all layerSets
    for(var g =0;g<LSets;g++){
         activeDocument.activeLayer = activeDocument.layerSets;
         var lName = activeDocument.activeLayer.name;
         var saveFile= File(outputFolder+ "/" + getName(g,lName));
    dupLayers();
        if(win.g12.cb1.value){
        try{activeDocument.mergeVisibleLayers();}catch(e){}
        }
    if(win.g12.cb2.value){
         try{activeDocument.trim(TrimType.TRANSPARENT,true,true,true,true);}catch(e){}
         }
    SaveDOC(saveFile);
    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
        }
    }//End Save all layerSets
if(win.g5.rb5.value){//Save all layerSets along with the top layer
    activeDocument.activeLayer = activeDocument.layers[0];
    var TopIDX =getSelectedLayersIdx();
     for(var g =0;g<LSets;g++){
         activeDocument.activeLayer = activeDocument.layerSets;
         var lName = activeDocument.activeLayer.name;
         selectLayerByIndex(Number(TopIDX[0]),true);
         var saveFile= File(outputFolder+ "/" + getName(g,lName));
    dupLayers();
        if(win.g12.cb1.value){
        try{activeDocument.mergeVisibleLayers();}catch(e){}
        }
    if(win.g12.cb2.value){
         try{activeDocument.trim(TrimType.TRANSPARENT,true,true,true,true);}catch(e){}
         }
    SaveDOC(saveFile);
    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
        }
    }//End Save all layerSets along with the top layer
if(win.g5.rb6.value){//Save all layerSets along with background layer
         for(var g =0;g<LSets;g++){
         activeDocument.activeLayer = activeDocument.layerSets;
         var lName = activeDocument.activeLayer.name;
         selectLayerByIndex(0,true);
         var saveFile= File(outputFolder+ "/" + getName(g,lName));
    dupLayers();
        if(win.g12.cb1.value){
        try{activeDocument.mergeVisibleLayers();}catch(e){}
        }
    if(win.g12.cb2.value){
         try{activeDocument.trim(TrimType.TRANSPARENT,true,true,true,true);}catch(e){}
         }
    SaveDOC(saveFile);
    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
        }
    }//End Save all layerSets along with background layer
        }
}
function getName(seq,lName){
seq = zeroPad((Number(seq)+1), 3);
var dName = decodeURI(activeDocument.name).replace(/\.[^\.]+$/, '');
var Name ='';
switch (Number(win.g15.dd1.selection.index)){
    case 0: Name += lName; break;
    case 1: Name += dName +"-"+seq; break;
    case 2: Name += dName +"-"+ lName; break;
    case 3: Name += win.g15.et1.text + "-"+seq; break;
    default :break;
    }
return Name;
    }
function SaveDOC(saveFile){
    switch(Number(win.g18.dd1.selection.index)){
        case 0 : SavePNG(File(saveFile+".png")); break;
        case 1:  SavePSD(File(saveFile+".psd")); break;
        case 2:  SavePDF(File(saveFile+".pdf")); break;
        case 3:  SaveTIFF(File(saveFile+".tif")); break;
        case 3:  SaveJPG(File(saveFile+".jpg"),8); break;
        default : break;
        }
    }
}
main();
function hasBackground() {
   var ref = new ActionReference();
   ref.putProperty( charIDToTypeID("Prpr"), charIDToTypeID( "Bckg" ));
   ref.putEnumerated(charIDToTypeID( "Lyr " ),charIDToTypeID( "Ordn" ),charIDToTypeID( "Back" ));
   var desc =  executeActionGet(ref);
   var res = desc.getBoolean(charIDToTypeID( "Bckg" ));
   return res   
}
function getSelectedLayersIdx(){
      var selectedLayers = new Array;
      var ref = new ActionReference();
      ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
      var desc = executeActionGet(ref);
      if( desc.hasKey( stringIDToTypeID( 'targetLayers' ) ) ){
         desc = desc.getList( stringIDToTypeID( 'targetLayers' ));
          var c = desc.count
          var selectedLayers = new Array();
          for(var i=0;i<c;i++){
            try{
               activeDocument.backgroundLayer;
               selectedLayers.push(  desc.getReference( i ).getIndex() );
            }catch(e){
               selectedLayers.push(  desc.getReference( i ).getIndex()+1 );
            }
          }
       }else{
         var ref = new ActionReference();
         ref.putProperty( charIDToTypeID("Prpr") , charIDToTypeID( "ItmI" ));
         ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
         try{
            activeDocument.backgroundLayer;
            selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" ))-1);
         }catch(e){
            selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" )));
         }
      }
      return selectedLayers;
};
function isLayerSet(idx) {        
   var ref = new ActionReference();
   ref.putIndex(1283027488, idx);
   var desc =  executeActionGet(ref);
   var type = desc.getEnumerationValue(stringIDToTypeID("layerSection"));
   var res = typeIDToStringID(type);
   if(res == 'layerSectionStart') return true;
       return false;  
}
function dupLayers() {
    var desc143 = new ActionDescriptor();
        var ref73 = new ActionReference();
        ref73.putClass( charIDToTypeID('Dcmn') );
    desc143.putReference( charIDToTypeID('null'), ref73 );
    desc143.putString( charIDToTypeID('Nm  '), activeDocument.activeLayer.name );
        var ref74 = new ActionReference();
        ref74.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
    desc143.putReference( charIDToTypeID('Usng'), ref74 );
    executeAction( charIDToTypeID('Mk  '), desc143, DialogModes.NO );
};
function selectLayerByIndex(index,add){
add = (add == undefined)  ? add = false : add;
var ref = new ActionReference();
    ref.putIndex(charIDToTypeID("Lyr "), index);
    var desc = new ActionDescriptor();
    desc.putReference(charIDToTypeID("null"), ref );
       if(add) desc.putEnumerated( stringIDToTypeID( "selectionModifier" ), stringIDToTypeID( "selectionModifierType" ), stringIDToTypeID( "addToSelection" ) );
      desc.putBoolean( charIDToTypeID( "MkVs" ), false );
   try{
    executeAction(charIDToTypeID("slct"), desc, DialogModes.NO );
}catch(e){}
};
function selectAllLayers(layer) {//does not select background layer
if(layer == undefined) layer = 0;
activeDocument.activeLayer = activeDocument.layers[activeDocument.layers.length-1];
if(activeDocument.activeLayer.isBackgroundLayer)
activeDocument.activeLayer = activeDocument.layers[activeDocument.layers.length-2];
var BL = activeDocument.activeLayer.name;
activeDocument.activeLayer = activeDocument.layers[layer];
    var desc5 = new ActionDescriptor();
        var ref3 = new ActionReference();
        ref3.putName( charIDToTypeID('Lyr '), BL);
    desc5.putReference( charIDToTypeID('null'), ref3 );
    desc5.putEnumerated( stringIDToTypeID('selectionModifier'), stringIDToTypeID('selectionModifierType'), stringIDToTypeID('addToSelectionContinuous') );
    desc5.putBoolean( charIDToTypeID('MkVs'), false );
    executeAction( charIDToTypeID('slct'), desc5, DialogModes.NO );
};
function zeroPad(n, s) {
   n = n.toString();
   while (n.length < s)  n = '0' + n;
   return n;
}
function SavePNG(saveFile){
    pngSaveOptions = new PNGSaveOptions();
activeDocument.saveAs(saveFile, pngSaveOptions, true, Extension.LOWERCASE);
}
function SaveTIFF(saveFile){
tiffSaveOptions = new TiffSaveOptions();
tiffSaveOptions.embedColorProfile = true;
tiffSaveOptions.alphaChannels = true;
tiffSaveOptions.layers = true;
tiffSaveOptions.imageCompression = TIFFEncoding.TIFFLZW;
activeDocument.saveAs(saveFile, tiffSaveOptions, true, Extension.LOWERCASE);
}
function SavePSD(saveFile){
psdSaveOptions = new PhotoshopSaveOptions();
psdSaveOptions.embedColorProfile = true;
psdSaveOptions.alphaChannels = true; 
activeDocument.saveAs(saveFile, psdSaveOptions, true, Extension.LOWERCASE);
}
function SavePDF(saveFile){
pdfSaveOptions = new PDFSaveOptions();
activeDocument.saveAs(saveFile, pdfSaveOptions, true, Extension.LOWERCASE);
}
function SaveJPG(saveFile, jpegQuality){
jpgSaveOptions = new JPEGSaveOptions();
jpgSaveOptions.embedColorProfile = true;
jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
jpgSaveOptions.matte = MatteType.NONE;
jpgSaveOptions.quality = jpegQuality; //1-12
activeDocument.saveAs(saveFile, jpgSaveOptions, true,Extension.LOWERCASE);
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 19, 2011 May 19, 2011

Copy link to clipboard

Copied

Thank you! I'll tinker with this. Very nice interface. Kudos! Do you still want that beer money? Send me your Paypal email...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
May 19, 2011 May 19, 2011

Copy link to clipboard

Copied

Everything is free here, enjoy!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jul 01, 2011 Jul 01, 2011

Copy link to clipboard

Copied

very nice and helpful script!   thanks

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 20, 2011 Jul 20, 2011

Copy link to clipboard

Copied

Paul, this script is GREAT, and has nearly everything I need. Very nice indeed. I'm just getting exposed to scripting and hope to dive in myself soo.

That said, I have a few things happening that I would greatly appreciate help with...

In Paul's above script (which I have not modified), the 'save to jpg' function is buggy for me. Once I choose my settings and destination folder and activate the script, the output JPG files are 'blackholing.' They are just not ending up anywhere. PNG works fine.

I wonder if anyone might take a look at this with me?

Beyond getting JPG outp[ut to work, I can see one modification that would really make this script that much more powerful: Being able to include top and/or bottom LAYERSETS, instead of just layers. How involved is that kind of mod?

But really, the script is great and quite powerful. I just need the JPG output to work iin the near term.

Help, anyone?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 20, 2011 Jul 20, 2011

Copy link to clipboard

Copied

Just to be clear, the script I'm referring to is Paul's from May 19, 2011 5:18 PM.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Jul 20, 2011 Jul 20, 2011

Copy link to clipboard

Copied

Sorry about saving as jpg not working, I have now fixed that error and the new file can be downloaded from:-

http://www.scriptsrus.talktalk.net/

I will also have a look at adding the extra options as you have described.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 20, 2011 Jul 20, 2011

Copy link to clipboard

Copied

That is simply marvelous.

The saving of top and bottom groups would be quite helpful when it comes to baking in a flexible variety of fades and backgrounds into output images.

Very cool of you, and many thanks.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Jul 20, 2011 Jul 20, 2011

Copy link to clipboard

Copied

I have just added those options and is ready to be downloaded.

All the best.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 22, 2011 Jul 22, 2011

Copy link to clipboard

Copied

Paul, that is great, great stuff.

I know I'm likely teetering on the edge of asking for one too many favors, but something that would be quite useful is the addition of an option to:

Save all layerSets along with the top and bottom layerSets

That way, users could bake in a top effect, say, a fade or the like, along with a background.

Possible?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Jul 23, 2011 Jul 23, 2011

Copy link to clipboard

Copied

No Problem, it's done and ready to download

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 22, 2016 Aug 22, 2016

Copy link to clipboard

Copied

Hi Paul,

But in the above script save to .jpg format is not working in interface i don't know why and also i want my background layer and top layer also to be visible in all group jpegs

#target photoshop 

function main(){ 

var LSets = activeDocument.layerSets.length; 

var ArtLayers = activeDocument.artLayers.length; 

var NoOfLayers = activeDocument.layers.length; 

var Back = hasBackground(); 

var hasTop = false; 

var selLayers =getSelectedLayersIdx(); 

var selGroups=[]; 

if(LSets>0){ 

    for(var s in selLayers){ 

   if(isLayerSet(selLayers)) selGroups.push(selLayers); 

        } 

    } 

if(activeDocument.layers[0].typename == 'ArtLayer') hasTop = true; 

var win = new Window('dialog','Layer Saver'); 

g = win.graphics; 

var myBrush = g.newBrush(g.BrushType.SOLID_COLOR, [0.99, 0.99, 0.99, 1]); 

g.backgroundColor = myBrush; 

win.p1= win.add("panel", undefined, undefined, {borderStyle:"black"});  

win.p1.preferredSize=[500,20]; 

win.g1 = win.p1.add('group'); 

win.g1.orientation = "row"; 

win.title = win.g1.add('statictext',undefined,'Layer Saver'); 

win.title.alignment="fill"; 

var g = win.title.graphics; 

g.font = ScriptUI.newFont("Georgia","BOLDITALIC",22); 

win.g5 =win.p1.add('group'); 

win.g5.orientation = "column"; 

win.g5.alignChildren='left'; 

win.g5.spacing=0; 

if(LSets == 0){ 

win.g5.rb1 = win.g5.add('radiobutton',undefined,'Save selected layers'); 

win.g5.rb2 = win.g5.add('radiobutton',undefined,'Save selected layers along with the top layer'); 

win.g5.rb3 = win.g5.add('radiobutton',undefined,'Save selected layers along with background layer'); 

win.g5.rb4 = win.g5.add('radiobutton',undefined,'Save all layers'); 

win.g5.rb5 = win.g5.add('radiobutton',undefined,'Save all layers along with the top layer'); 

win.g5.rb6 = win.g5.add('radiobutton',undefined,'Save all layers along with background layer'); 

win.g5.rb3.enabled=Back; 

win.g5.rb6.enabled=Back; 

win.g5.rb4.value=true; 

}else{ 

win.g5.rb1 = win.g5.add('radiobutton',undefined,'Save selected layerSets'); 

win.g5.rb2 = win.g5.add('radiobutton',undefined,'Save selected layerSets along with the top layer'); 

win.g5.rb3 = win.g5.add('radiobutton',undefined,'Save selected layerSets along with background layer'); 

win.g5.rb4 = win.g5.add('radiobutton',undefined,'Save all layerSets'); 

win.g5.rb5 = win.g5.add('radiobutton',undefined,'Save all layerSets along with the top layer'); 

win.g5.rb6 = win.g5.add('radiobutton',undefined,'Save all layerSets along with background layer'); 

win.g5.rb3.enabled=Back; 

win.g5.rb6.enabled=Back; 

win.g5.rb2.enabled=hasTop; 

win.g5.rb5.enabled=hasTop; 

if(selGroups.length <1){ 

    win.g5.rb1.enabled=false; 

    win.g5.rb2.enabled=false; 

    win.g5.rb3.enabled=false; 

    } 

win.g5.rb4.value=true; 

    } 

win.p2 = win.add("panel", undefined, undefined, {borderStyle:"black"}); 

win.p2.preferredSize=[500,20]; 

win.p2.st1 = win.p2.add('statictext',undefined,'Output details'); 

win.p2.st1.graphics.font = ScriptUI.newFont("Tahoma", "Bold", 18); 

win.g10 =win.p2.add('group'); 

win.g10.orientation = "row"; 

win.g10.alignment='left'; 

win.g10.et1 = win.g10.add('edittext'); 

win.g10.et1.preferredSize=[350,20]; 

win.g10.bu1 = win.g10.add('button',undefined,'Select Folder'); 

win.g10.bu1.onClick=function(){ 

var Folder1 = Folder(app.activeDocument.path); 

outputFolder = Folder.selectDialog("Please select the output folder",Folder1);  

if(outputFolder !=null){ 

  win.g10.et1.text =  decodeURI(outputFolder.fsName);  

  } 

win.g12 =win.p2.add('group'); 

win.g12.orientation = "row"; 

win.g12.alignment='left'; 

win.g12.cb1 = win.g12.add('checkbox',undefined,'Merge Visible Layers?'); 

win.g12.cb2 = win.g12.add('checkbox',undefined,'Trim Layer'); 

win.g15 =win.p2.add('group'); 

win.g15.orientation = "row"; 

win.g15.alignment='left'; 

var Options= ["Layer/Group Name","FileName + Sequence No.","FileName + Layer/Group Name ","User Defined with Sequence No."]; 

win.g15.st1 = win.g15.add('statictext',undefined,'Save Options..'); 

win.g15.dd1 = win.g15.add('dropdownlist',undefined,Options); 

win.g15.dd1.selection=0; 

win.g15.et1 = win.g15.add('edittext'); 

win.g15.et1.preferredSize=[150,20]; 

win.g15.et1.hide(); 

win.g15.dd1.onChange=function(){ 

  if(this.selection.index==3){ 

      win.g15.et1.show(); 

      }else{ 

          win.g15.et1.hide(); 

          } 

    } 

win.g18 =win.p2.add('group'); 

win.g18.orientation = "row"; 

win.g18.st1 = win.g18.add('statictext',undefined,'Save as :'); 

var Types = ["PNG","PSD","PDF","TIF","JPG"]; 

win.g18.dd1 = win.g18.add('dropdownlist',undefined,Types); 

win.g18.dd1.selection = 0; 

win.g18.alignment='left'; 

win.g20 =win.p2.add('group'); 

win.g20.orientation = "row"; 

win.g20.bu1 = win.g20.add('button',undefined,'Process'); 

win.g20.bu1.preferredSize=[200,35]; 

win.g20.bu2 = win.g20.add('button',undefined,'Cancel'); 

win.g20.bu2.preferredSize=[200,35]; 

win.g20.bu1.onClick=function(){ 

    if(win.g10.et1.text == ''){ 

        alert("No Output Folder has been Selected!"); 

        return; 

        } 

    if(win.g15.dd1.selection.index==3){ 

        if(win.g15.et1.text ==''){ 

            alert("No FileName Has Been Entered!"); 

            return; 

            } 

        } 

    win.close(1); 

Process(); 

win.center(); 

win.show(); 

function Process(){ 

if(LSets == 0){ 

//Process layers only 

if(win.g5.rb1.value){//Save selected layers 

for(var b in selLayers){ 

    selectLayerByIndex(Number(selLayers)); 

     var lName = activeDocument.activeLayer.name; 

    var saveFile= File(outputFolder+ "/" + getName(b,lName)); 

    dupLayers(); 

    if(win.g12.cb1.value){ 

        try{activeDocument.mergeVisibleLayers();}catch(e){} 

        } 

     if(win.g12.cb2.value){ 

         try{activeDocument.trim(TrimType.TRANSPARENT,true,true,true,true);}catch(e){} 

         } 

    SaveDOC(saveFile); 

    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES); 

    } 

    }//End Save selected layers 

if(win.g5.rb2.value){//Save selected layers along with the top layer 

for(var b in selLayers){ 

    selectLayerByIndex(Number(selLayers)); 

     var lName = activeDocument.activeLayer.name; 

    activeDocument.activeLayer= activeDocument.layers[0]; 

    selectLayerByIndex(Number(selLayers),true); 

    var saveFile= File(outputFolder+ "/" + getName(b,lName)); 

    dupLayers(); 

    if(win.g12.cb1.value){ 

        try{activeDocument.mergeVisibleLayers();}catch(e){} 

        } 

    if(win.g12.cb2.value){ 

         try{activeDocument.trim(TrimType.TRANSPARENT,true,true,true,true);}catch(e){} 

         } 

    SaveDOC(saveFile); 

    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES); 

    } 

    }//End Save selected layers along with the top layer 

if(win.g5.rb3.value){//Save selected layers along with background layer 

    for(var b in selLayers){ 

    selectLayerByIndex(Number(selLayers)); 

     var lName = activeDocument.activeLayer.name; 

    activeDocument.activeLayer = activeDocument.layers[activeDocument.layers.length-1]; 

    selectLayerByIndex(Number(selLayers),true); 

    var saveFile= File(outputFolder+ "/" + getName(b,lName)); 

    dupLayers(); 

        if(win.g12.cb1.value){ 

        try{activeDocument.mergeVisibleLayers();}catch(e){} 

        } 

    if(win.g12.cb2.value){ 

         try{activeDocument.trim(TrimType.TRANSPARENT,true,true,true,true);}catch(e){} 

         } 

    SaveDOC(saveFile); 

    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES); 

    } 

    }//End Save selected layers along with background layer 

if(win.g5.rb4.value){//Save all layers 

selectAllLayers(); 

selLayers =getSelectedLayersIdx(); 

for(var b in selLayers){ 

     selectLayerByIndex(Number(selLayers)); 

     var lName = activeDocument.activeLayer.name; 

    var saveFile= File(outputFolder+ "/" + getName(b,lName)); 

    dupLayers(); 

        if(win.g12.cb1.value){ 

        try{activeDocument.mergeVisibleLayers();}catch(e){} 

        } 

    if(win.g12.cb2.value){ 

         try{activeDocument.trim(TrimType.TRANSPARENT,true,true,true,true);}catch(e){} 

         } 

    SaveDOC(saveFile); 

    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES); 

     } 

    }//End Save all layers 

if(win.g5.rb5.value){//Save all layers along with the top layer 

selectAllLayers(1); 

selLayers =getSelectedLayersIdx(); 

for(var b in selLayers){ 

    selectLayerByIndex(Number(selLayers)); 

     var lName = activeDocument.activeLayer.name; 

    activeDocument.activeLayer = activeDocument.layers[0]; 

    selectLayerByIndex(Number(selLayers),true); 

    var saveFile= File(outputFolder+ "/" + getName(b,lName)); 

    dupLayers(); 

        if(win.g12.cb1.value){ 

        try{activeDocument.mergeVisibleLayers();}catch(e){} 

        } 

    if(win.g12.cb2.value){ 

         try{activeDocument.trim(TrimType.TRANSPARENT,true,true,true,true);}catch(e){} 

         } 

    SaveDOC(saveFile); 

    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES); 

    } 

    }//End Save all layers along with the top layer 

if(win.g5.rb6.value){//Save all layers along with background layer 

selectAllLayers(); 

selLayers =getSelectedLayersIdx(); 

    for(var b in selLayers){ 

    selectLayerByIndex(Number(selLayers)); 

     var lName = activeDocument.activeLayer.name; 

    activeDocument.activeLayer = activeDocument.layers[activeDocument.layers.length-1]; 

    selectLayerByIndex(Number(selLayers),true); 

    var saveFile= File(outputFolder+ "/" + getName(b,lName)); 

    dupLayers(); 

        if(win.g12.cb1.value){ 

        try{activeDocument.mergeVisibleLayers();}catch(e){} 

        } 

    if(win.g12.cb2.value){ 

         try{activeDocument.trim(TrimType.TRANSPARENT,true,true,true,true);}catch(e){} 

         } 

    SaveDOC(saveFile); 

    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES); 

    } 

    }//End Save all layers along with background layer 

    }else{ 

//Process LayerSets Only 

if(win.g5.rb1.value){//Save selected layerSets 

    for(var g in selGroups){ 

        selectLayerByIndex(Number(selGroups)); 

        var lName = activeDocument.activeLayer.name; 

        var saveFile= File(outputFolder+ "/" + getName(g,lName)); 

        dupLayers(); 

            if(win.g12.cb1.value){ 

        try{activeDocument.mergeVisibleLayers();}catch(e){} 

        } 

    if(win.g12.cb2.value){ 

         try{activeDocument.trim(TrimType.TRANSPARENT,true,true,true,true);}catch(e){} 

         } 

    SaveDOC(saveFile); 

    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES); 

        } 

   }//End Save selected layerSets 

if(win.g5.rb2.value){//Save selected layerSets along with the top layer 

    for(var g in selGroups){ 

        selectLayerByIndex(Number(selGroups)); 

     var lName = activeDocument.activeLayer.name; 

    activeDocument.activeLayer= activeDocument.layers[0]; 

    selectLayerByIndex(Number(selGroups),true); 

    var saveFile= File(outputFolder+ "/" + getName(g,lName)); 

    dupLayers(); 

        if(win.g12.cb1.value){ 

        try{activeDocument.mergeVisibleLayers();}catch(e){} 

        } 

    if(win.g12.cb2.value){ 

         try{activeDocument.trim(TrimType.TRANSPARENT,true,true,true,true);}catch(e){} 

         } 

    SaveDOC(saveFile); 

    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES); 

        } 

    }//End Save selected layerSets along with the top layer 

if(win.g5.rb3.value){//Save selected layerSets along with background layer 

    for(var g in selGroups){ 

    selectLayerByIndex(Number(selGroups)); 

     var lName = activeDocument.activeLayer.name; 

    activeDocument.activeLayer = activeDocument.layers[activeDocument.layers.length-1]; 

    selectLayerByIndex(Number(selGroups),true); 

    var saveFile= File(outputFolder+ "/" + getName(g,lName)); 

    dupLayers(); 

        if(win.g12.cb1.value){ 

        try{activeDocument.mergeVisibleLayers();}catch(e){} 

        } 

    if(win.g12.cb2.value){ 

         try{activeDocument.trim(TrimType.TRANSPARENT,true,true,true,true);}catch(e){} 

         } 

    SaveDOC(saveFile); 

    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES); 

    } 

    }//End Save selected layerSets along with background layer 

if(win.g5.rb4.value){//Save all layerSets 

    for(var g =0;g<LSets;g++){ 

         activeDocument.activeLayer = activeDocument.layerSets

         var lName = activeDocument.activeLayer.name; 

         var saveFile= File(outputFolder+ "/" + getName(g,lName)); 

    dupLayers(); 

        if(win.g12.cb1.value){ 

        try{activeDocument.mergeVisibleLayers();}catch(e){} 

        } 

    if(win.g12.cb2.value){ 

         try{activeDocument.trim(TrimType.TRANSPARENT,true,true,true,true);}catch(e){} 

         } 

    SaveDOC(saveFile); 

    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES); 

        } 

    }//End Save all layerSets 

if(win.g5.rb5.value){//Save all layerSets along with the top layer 

    activeDocument.activeLayer = activeDocument.layers[0]; 

    var TopIDX =getSelectedLayersIdx(); 

     for(var g =0;g<LSets;g++){ 

         activeDocument.activeLayer = activeDocument.layerSets

         var lName = activeDocument.activeLayer.name; 

         selectLayerByIndex(Number(TopIDX[0]),true); 

         var saveFile= File(outputFolder+ "/" + getName(g,lName)); 

    dupLayers(); 

        if(win.g12.cb1.value){ 

        try{activeDocument.mergeVisibleLayers();}catch(e){} 

        } 

    if(win.g12.cb2.value){ 

         try{activeDocument.trim(TrimType.TRANSPARENT,true,true,true,true);}catch(e){} 

         } 

    SaveDOC(saveFile); 

    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES); 

        } 

    }//End Save all layerSets along with the top layer 

if(win.g5.rb6.value){//Save all layerSets along with background layer 

         for(var g =0;g<LSets;g++){ 

         activeDocument.activeLayer = activeDocument.layerSets

         var lName = activeDocument.activeLayer.name; 

         selectLayerByIndex(0,true); 

         var saveFile= File(outputFolder+ "/" + getName(g,lName)); 

    dupLayers(); 

        if(win.g12.cb1.value){ 

        try{activeDocument.mergeVisibleLayers();}catch(e){} 

        } 

    if(win.g12.cb2.value){ 

         try{activeDocument.trim(TrimType.TRANSPARENT,true,true,true,true);}catch(e){} 

         } 

    SaveDOC(saveFile); 

    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES); 

        } 

    }//End Save all layerSets along with background layer 

        } 

function getName(seq,lName){ 

seq = zeroPad((Number(seq)+1), 3); 

var dName = decodeURI(activeDocument.name).replace(/\.[^\.]+$/, ''); 

var Name =''; 

switch (Number(win.g15.dd1.selection.index)){ 

    case 0: Name += lName; break; 

    case 1: Name += dName +"-"+seq; break; 

    case 2: Name += dName +"-"+ lName; break; 

    case 3: Name += win.g15.et1.text + "-"+seq; break; 

    default :break; 

    } 

return Name; 

    } 

function SaveDOC(saveFile){ 

    switch(Number(win.g18.dd1.selection.index)){ 

        case 0 : SavePNG(File(saveFile+".png")); break; 

        case 1:  SavePSD(File(saveFile+".psd")); break; 

        case 2:  SavePDF(File(saveFile+".pdf")); break; 

        case 3:  SaveTIFF(File(saveFile+".tif")); break; 

        case 3:  SaveJPG(File(saveFile+".jpg"),8); break; 

        default : break; 

        } 

    } 

main(); 

function hasBackground() {  

   var ref = new ActionReference();  

   ref.putProperty( charIDToTypeID("Prpr"), charIDToTypeID( "Bckg" ));  

   ref.putEnumerated(charIDToTypeID( "Lyr " ),charIDToTypeID( "Ordn" ),charIDToTypeID( "Back" )); 

   var desc =  executeActionGet(ref);  

   var res = desc.getBoolean(charIDToTypeID( "Bckg" ));  

   return res     

}  

function getSelectedLayersIdx(){  

      var selectedLayers = new Array;  

      var ref = new ActionReference();  

      ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );  

      var desc = executeActionGet(ref);  

      if( desc.hasKey( stringIDToTypeID( 'targetLayers' ) ) ){  

         desc = desc.getList( stringIDToTypeID( 'targetLayers' ));  

          var c = desc.count  

          var selectedLayers = new Array();  

          for(var i=0;i<c;i++){  

            try{  

               activeDocument.backgroundLayer;  

               selectedLayers.push(  desc.getReference( i ).getIndex() );  

            }catch(e){  

               selectedLayers.push(  desc.getReference( i ).getIndex()+1 );  

            }  

          }  

       }else{  

         var ref = new ActionReference();  

         ref.putProperty( charIDToTypeID("Prpr") , charIDToTypeID( "ItmI" ));  

         ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );  

         try{  

            activeDocument.backgroundLayer;  

            selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" ))-1);  

         }catch(e){  

            selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" )));  

         }  

      }  

      return selectedLayers;  

}; 

function isLayerSet(idx) {          

   var ref = new ActionReference();  

   ref.putIndex(1283027488, idx);  

   var desc =  executeActionGet(ref);  

   var type = desc.getEnumerationValue(stringIDToTypeID("layerSection"));  

   var res = typeIDToStringID(type);  

   if(res == 'layerSectionStart') return true; 

       return false;    

}  

function dupLayers() {  

    var desc143 = new ActionDescriptor(); 

        var ref73 = new ActionReference(); 

        ref73.putClass( charIDToTypeID('Dcmn') ); 

    desc143.putReference( charIDToTypeID('null'), ref73 ); 

    desc143.putString( charIDToTypeID('Nm  '), activeDocument.activeLayer.name ); 

        var ref74 = new ActionReference(); 

        ref74.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') ); 

    desc143.putReference( charIDToTypeID('Usng'), ref74 ); 

    executeAction( charIDToTypeID('Mk  '), desc143, DialogModes.NO ); 

}; 

function selectLayerByIndex(index,add){  

add = (add == undefined)  ? add = false : add; 

var ref = new ActionReference(); 

    ref.putIndex(charIDToTypeID("Lyr "), index); 

    var desc = new ActionDescriptor(); 

    desc.putReference(charIDToTypeID("null"), ref ); 

       if(add) desc.putEnumerated( stringIDToTypeID( "selectionModifier" ), stringIDToTypeID( "selectionModifierType" ), stringIDToTypeID( "addToSelection" ) );  

      desc.putBoolean( charIDToTypeID( "MkVs" ), false );  

   try{ 

    executeAction(charIDToTypeID("slct"), desc, DialogModes.NO ); 

}catch(e){} 

}; 

function selectAllLayers(layer) {//does not select background layer 

if(layer == undefined) layer = 0; 

activeDocument.activeLayer = activeDocument.layers[activeDocument.layers.length-1]; 

if(activeDocument.activeLayer.isBackgroundLayer)  

activeDocument.activeLayer = activeDocument.layers[activeDocument.layers.length-2]; 

var BL = activeDocument.activeLayer.name; 

activeDocument.activeLayer = activeDocument.layers[layer]; 

    var desc5 = new ActionDescriptor(); 

        var ref3 = new ActionReference(); 

        ref3.putName( charIDToTypeID('Lyr '), BL); 

    desc5.putReference( charIDToTypeID('null'), ref3 ); 

    desc5.putEnumerated( stringIDToTypeID('selectionModifier'), stringIDToTypeID('selectionModifierType'), stringIDToTypeID('addToSelectionContinuous') ); 

    desc5.putBoolean( charIDToTypeID('MkVs'), false ); 

    executeAction( charIDToTypeID('slct'), desc5, DialogModes.NO ); 

}; 

function zeroPad(n, s) {  

   n = n.toString();  

   while (n.length < s)  n = '0' + n;  

   return n;  

function SavePNG(saveFile){ 

    pngSaveOptions = new PNGSaveOptions();  

activeDocument.saveAs(saveFile, pngSaveOptions, true, Extension.LOWERCASE);  

function SaveTIFF(saveFile){ 

tiffSaveOptions = new TiffSaveOptions();  

tiffSaveOptions.embedColorProfile = true;  

tiffSaveOptions.alphaChannels = true;  

tiffSaveOptions.layers = true; 

tiffSaveOptions.imageCompression = TIFFEncoding.TIFFLZW;  

activeDocument.saveAs(saveFile, tiffSaveOptions, true, Extension.LOWERCASE);  

function SavePSD(saveFile){  

psdSaveOptions = new PhotoshopSaveOptions();  

psdSaveOptions.embedColorProfile = true;  

psdSaveOptions.alphaChannels = true;   

activeDocument.saveAs(saveFile, psdSaveOptions, true, Extension.LOWERCASE);  

function SavePDF(saveFile){  

pdfSaveOptions = new PDFSaveOptions();  

activeDocument.saveAs(saveFile, pdfSaveOptions, true, Extension.LOWERCASE);  

function SaveJPG(saveFile, jpegQuality){ 

jpgSaveOptions = new JPEGSaveOptions(); 

jpgSaveOptions.embedColorProfile = true; 

jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE; 

jpgSaveOptions.matte = MatteType.NONE; 

jpgSaveOptions.quality = jpegQuality; //1-12 

activeDocument.saveAs(saveFile, jpgSaveOptions, true,Extension.LOWERCASE); 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines