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

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

114.8K

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
Community Expert ,
Sep 07, 2009 Sep 07, 2009

Copy link to clipboard

Copied

Are all the groups on the topmost hierarchical level or are there groups within 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 ,
Sep 08, 2009 Sep 08, 2009

Copy link to clipboard

Copied

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 = 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	
		pdfOpts = new PDFSaveOptions() ;
		pdfOpts.embedColorProfile = true;
		pdfOpts.PDFCompatibility =  PDFCompatibility.PDF13;
		pdfOpts.downSample =  PDFResample.NONE;
		pdfOpts.vectorData = true;
		pdfOpts.alphaChannels = false;
		pdfOpts.byteOrder = ByteOrder.MACOS; 
		pdfOpts.layers = false ;
		pdfOpts.preserveEditing = false ;
		pdfOpts.convertToEightBit = true;
		pdfOpts.annotations = false;
		pdfOpts.colorConversion = false;
		pdfOpts.embedFonts = true;
		pdfOpts.embedThumbnail = true;
		pdfOpts.transparency = false;
		pdfOpts.encoding = PDFEncoding.PDFZIP ;	
		var theVisibilities = new Array;
// 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.saveAs((new File(theDestination+"/"+myDocName+aSuffix+aLayerName+theNumberString+".pdf")),pdfOpts,true)
			};
		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
New Here ,
Sep 09, 2009 Sep 09, 2009

Copy link to clipboard

Copied

Yes, the Groups are all at the top level, and YES! your script worked wonderfully!  I'll need to figure out the jpg instead of pdf portion, but you definitely solved the difficult part. Thank you!!

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 ,
Sep 09, 2009 Sep 09, 2009

Copy link to clipboard

Copied

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

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 16, 2010 Mar 16, 2010

Copy link to clipboard

Copied

Great skript!

Is there a way to export Groups to png?

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 ,
Jun 08, 2010 Jun 08, 2010

Copy link to clipboard

Copied

Groups to .png is what I*m searching for, too.

Any ideas? 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
Valorous Hero ,
Jun 08, 2010 Jun 08, 2010

Copy link to clipboard

Copied

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.name);
dupLayers();
var saveFile= File(oldPath +"/"+doc.layerSets
.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);
}

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 ,
Jun 10, 2010 Jun 10, 2010

Copy link to clipboard

Copied

Great script Paul!

I've added

     activeDocument.trim(TrimType.TRANSPARENT,true,true,true,true);

before

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

so the PNG files are trimmed before saving.

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 29, 2010 Sep 29, 2010

Copy link to clipboard

Copied

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

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 ,
Sep 29, 2010 Sep 29, 2010

Copy link to clipboard

Copied

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.name);
dupLayers();
activeDocument.mergeVisibleLayers();
activeDocument.trim(TrimType.TRANSPARENT,true...
.name +".png");
SavePNG(saveFile);
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
    }
}
main()...










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);
}

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 ,
Sep 14, 2011 Sep 14, 2011

Copy link to clipboard

Copied

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

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 ,
Sep 15, 2011 Sep 15, 2011

Copy link to clipboard

Copied

The Script from which post are you referring to exactly?

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 ,
Sep 15, 2011 Sep 15, 2011

Copy link to clipboard

Copied

Have you tried this one?

Layer Saver

 

This supports jpeg

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 ,
Sep 15, 2011 Sep 15, 2011

Copy link to clipboard

Copied

You are an absolute legend. Thanks mate. You saved my life. thanks thanks 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 ,
Dec 21, 2011 Dec 21, 2011

Copy link to clipboard

Copied

Fantastic script!  Is there a way to have this script combine the exported JPG's or PDF's into a single PDF?

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 ,
Dec 21, 2011 Dec 21, 2011

Copy link to clipboard

Copied

Sorry but the option of creating multipage PDFs was removed in Photoshop CS4 and that functionality was moved to Bridge and that process is not scriptable.

So if you have Photoshop CS2 or CS3 you could open all the JPGs and use File - Automate - PDF Presentation to create your pdf.

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 ,
Nov 28, 2013 Nov 28, 2013

Copy link to clipboard

Copied

Hi Paul,

The link is down, can you upload it again?

This script 'd really save me some valuable time

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 ,
Nov 28, 2013 Nov 28, 2013

Copy link to clipboard

Copied

try this, the layer saver is towards the bottom of the list:

http://www.ps-bridge-scripts.talktalk.net/

Paul makes some very useful scripts, 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
Community Expert ,
Nov 28, 2013 Nov 28, 2013

Copy link to clipboard

Copied

Paul makes some very useful scripts, thanks!

Alas, if I remember correctly he stopped participating in these Fora because of his frustration with Adobe’s bug fixing neglect.

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 ,
Sep 28, 2018 Sep 28, 2018

Copy link to clipboard

Copied

Could you please help me to Export Artboards PNG and Ai?

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 ,
Nov 13, 2018 Nov 13, 2018

Copy link to clipboard

Copied

Thanks a lot for this script! It helps me and automate my routine work !!!
Does the script make all other layers invisible when export the current group? May I change it? I need some layers that I choose visible stay visible during exporting groups. For example I made a storyboard. And it has in the bottom unchangeable bg white colors and a picture borders - white rectangle with black stroke, and in each group I draw frames, and in each group there aren't bg and picture borders. I switch off visibility of groups, but bg and borders are always visible. To see them on each jpg I should to copy and paste them in each group. Can I avoid it with your script?

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 ,
Nov 25, 2018 Nov 25, 2018

Copy link to clipboard

Copied

Which exact Script are you referring to?

Could you post a screenshot of the file’s Layers Panel to illustrate the Layer structure and clarify which Layers you want to »fixate«?

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 ,
Apr 24, 2015 Apr 24, 2015

Copy link to clipboard

Copied

Hello,

I'm looking to do the same (export all top level groups as images). Is there an updated script that works in CC?

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
Community Expert ,
Apr 26, 2015 Apr 26, 2015

Copy link to clipboard

Copied

Doe the Script fail for you in CC and if so how exactly?

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