Skip to main content
Hraw
Participating Frequently
July 11, 2017
Question

I need an action to stack multiple images (opened in ps) into multiple layers

  • July 11, 2017
  • 2 replies
  • 3192 views

Hi guys,

Hope somehone can help,

Can I create an action with this funcion? I usually move every image into the destination one as to create multiple layers, but how can I automatize it? I tried to create an action with Select, copy and paste but seems not working. I don't need the script>statistics>load file into stacks cause I need to open the image in photoshop first

Thanks in advance

This topic has been closed for replies.

2 replies

SuperMerlin
Inspiring
July 11, 2017

This code will stack all open documents into the first document.

#target photoshop;

while(app.documents.length>1){

app.activeDocument = app.documents[1];

var layerName = decodeURI(activeDocument.name).replace(/\....$/,'');

activeDocument.activeLayer.duplicate(documents[0]);

app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);

activeDocument.activeLayer.name = layerName;

};

erwins47989706
Participating Frequently
October 19, 2019

Hey, how can i use this script step by step, I have no experiece in this.

Cheers

Stephen Marsh
Community Expert
Community Expert
October 20, 2019
JJMack
Community Expert
Community Expert
July 11, 2017

No Actions can not use logic to retrieve the number of open document and their sizes then create a new document the correct size to house the currently open documents composite or Layers.  You would need to write a Photoshop Script to do that.

JJMack
Hraw
HrawAuthor
Participating Frequently
July 11, 2017

Thank you, how can I do it?

JJMack
Community Expert
Community Expert
July 11, 2017

This code will create a new document with a good size canvas for of stack of their composites. With  SuperMerlin script  I do not know what you will wind up with if the open document are layered  and are different sizes and resolutions.  He is a better scripter than me. Still it looks to me that his script will only stack the active layer from  each of other open document and close them without saving them. Loosing any changes not saved in those documents.

/* ==========================================================
// 2016  John J. McAssey (JJMack) 
// Stack the open Document Visible layer composite into a new 300 DPI document
// This script is supplied as is. It is provided as freeware. 
// The author accepts no liability for any problems arising from its use.
// ======================================================= */
// enable double-clicking from Mac Finder or Windows Explorer
#target photoshop // this command only works in Photoshop CS2 and higher
// bring application forward for double-click events
app.bringToFront();

if (documents.length >= 2) { main(); }
else alert("multiple Document are not open in Photoshop");	
///////////////////////////////////////////////////////////////////////////////
//                            main function                                  //
///////////////////////////////////////////////////////////////////////////////
function main() {
	var orig_ruler_units = app.preferences.rulerUnits;
	var orig_display_dialogs = app.displayDialogs;
	app.preferences.rulerUnits = Units.PIXELS;				// set the ruler units to PIXELS
	app.displayDialogs = DialogModes.NO;					// Set Dialogs off
	var closeDocs  = prompt("Should documents be Close without saving?", "Yes");	
	var canvasSize = new Array();							// what size canvas is needed
	canvasSize=getDocDementions();							// get max width and height of open documents
	app.togglePalettes();									// toggle off palette so Photoshop will not need to update them
	var doc = app.documents.add( canvasSize[0], canvasSize[1], 300, "Stacked Opened Documents", NewDocumentMode.RGB, DocumentFill.TRANSPARENT ); // create a new document
	//for (var i=0;i<documents.length-1;i++) {				// stack a layer for the open document into the new document	
	for (var i=documents.length-2;i>-1;i--) {				// stack a layer for the open document into the new document
		app.activeDocument = documents[i];					// switch active document
		var layerName = app.activeDocument.name;			// get document name	
		app.activeDocument.selection.selectAll();           // select all
		try {app.activeDocument.selection.copy(true);}		// copy composite of visible layers to clipboard
		catch (e) {try {app.activeDocument.selection.copy();} // copy composite of visible layers to clipboard
				   catch (e) {app.purge(PurgeTarget.CLIPBOARDCACHE);} // empty 
			}
		app.activeDocument.selection.deselect();			// deselect
		app.activeDocument = documents[documents.length-1];	// switch to newly created document
		try { app.activeDocument.paste(); }					// paste on composite of visible layers
		catch (e) { app.activeDocument.artLayers.add();	}	// add an empty layer
		app.activeDocument.activeLayer.name=layerName;		// label layer with Document name
		}
	if ( closeDocs == "Yes" ) closeAllButOne();				// close all opened document except the newly created document	
	app.togglePalettes();									// toggle user's palettes back on	
	app.runMenuItem(charIDToTypeID(("FtOn")));				// fit the document to the screen 
	app.displayDialogs = orig_display_dialogs;				// Reset display dialogs 
	app.preferences.rulerUnits = orig_ruler_units;			// reset units to original settings
	}
///////////////////////////////////////////////////////////////////////////////
//                           main function end                               //
///////////////////////////////////////////////////////////////////////////////
function getDocDementions(){
    width=0;
	height=0;
	for (var i=0;i<documents.length;i++) {					// look at open document sizes
	    if (documents[i].width > width) width=documents[i].width;
		if (documents[i].height > height) height=documents[i].height;
		}
	return new Array(width, height);						// return width and height
	}
	
function closeAllButOne(){									// close all opened document except the newly created document
	while  (documents.length>1) {							
		app.activeDocument = documents[0];		
		activeDocument.close(SaveOptions.DONOTSAVECHANGES);
		}
	}
JJMack