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?
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.
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«.
Thanks for this, it works really well. I've tried making 2 changes to the script but it doesn't seem to work right
What is wrong in this code?
Thanks for this, it works really well. I've tried making 2 changes to the script but it doesn't seem to work right
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
};
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.
You could try this..
#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[a].name);
dupLayers();
var saveFile= File(oldPath +"/"+doc.layerSets[a].name +".png");
SavePNG(saveFile);
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}
}
main();
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 SavePNG(saveFile){
pngSaveOptions = new PNGSaveOptions();
pngSaveOptions.embedColorProfile = true;
pngSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
pngSaveOptions.matte = MatteType.NONE;
pngSaveOptions.PNG8 = false;
pngSaveOptions.transparency = true;
activeDocument.saveAs(saveFile, pngSaveOptions, true, Extension.LOWERCASE);
}
Paul, This looks like a life saver script to me, but I am having a problem.
When I run it, it asks to save each group/file as a PSD.
I am an old time programmer, so I get the logic, but I don't know any of the syntax of photoshop scripting.
If i did I would try to sort this out myself.
Is there some overriding setting in preferences I need to change that won't just allow the script to save the group as a PNG (without my interaction) as the script seems to be telling it to do?
Thank you SO much.
Ed
There were a fewmistakes in that code, could you please try this now...
#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[a].name);
dupLayers();
activeDocument.mergeVisibleLayers();
activeDocument.trim(TrimType.TRANSPARENT,true,true,true,true);
var saveFile= File(oldPath +"/"+doc.layerSets[a].name +".png");
SavePNG(saveFile);
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}
}
main();
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 SavePNG(saveFile){
var pngOpts = new ExportOptionsSaveForWeb;
pngOpts.format = SaveDocumentType.PNG
pngOpts.PNG8 = false;
pngOpts.transparency = true;
pngOpts.interlaced = false;
pngOpts.quality = 100;
activeDocument.exportDocument(new File(saveFile),ExportType.SAVEFORWEB,pngOpts);
}
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[a].name);
dupLayers();
activeDocument.mergeVisibleLayers();
activeDocument.trim(TrimType.TRANSPARENT,true,true,true,true);
var saveFile= File(oldPath +"/"+doc.layerSets[a].name +".psd");
SavePSD(saveFile);
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}
}
main();
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 SavePSD(saveFile){
psdSaveOptions = new PhotoshopSaveOptions();
psdSaveOptions.embedColorProfile = true;
psdSaveOptions.alphaChannels = true;
activeDocument.saveAs(saveFile, psdSaveOptions, true, Extension.LOWERCASE);
}
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[s])) selGroups.push(selLayers[s]);
}
}
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[b]));
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[b]));
var lName = activeDocument.activeLayer.name;
activeDocument.activeLayer= activeDocument.layers[0];
selectLayerByIndex(Number(selLayers[b]),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[b]));
var lName = activeDocument.activeLayer.name;
activeDocument.activeLayer = activeDocument.layers[activeDocument.layers.length-1];
selectLayerByIndex(Number(selLayers[b]),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[b]));
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[b]));
var lName = activeDocument.activeLayer.name;
activeDocument.activeLayer = activeDocument.layers[0];
selectLayerByIndex(Number(selLayers[b]),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[b]));
var lName = activeDocument.activeLayer.name;
activeDocument.activeLayer = activeDocument.layers[activeDocument.layers.length-1];
selectLayerByIndex(Number(selLayers[b]),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[g]));
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[g]));
var lName = activeDocument.activeLayer.name;
activeDocument.activeLayer= activeDocument.layers[0];
selectLayerByIndex(Number(selGroups[g]),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[g]));
var lName = activeDocument.activeLayer.name;
activeDocument.activeLayer = activeDocument.layers[activeDocument.layers.length-1];
selectLayerByIndex(Number(selGroups[g]),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[g];
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[g];
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[g];
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);
}
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?
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.
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? ![]()
if you guys are still around, and can help I would love it. Exact same problems and needs to everyone here above. I have NO knowledge of editing scrips. The one for PDF worked but as you know really time consuming to then convert PDF to JPEGS. Can someone provide me the the script to download which works for converting the layer groups to .jpeg.
I would very very much appreciate it. I tried to edit the code for the script but very shamefull unsuccessful ![]()
Thank you
After 30 mins on Google I found this thread and downloaded the script for Layer Saver
I knew what I wanted to do, but not how to do it.
I have 100s of files each with up to 100 layers that I need to export as separate trimmed psd files
This script does it. It has saved me so much hassle and so a HUGE 'thank you' is due to you
and of course,
Seasons Greetings !
North America
Europe, Middle East and Africa
Asia Pacific