Here's my obligatory Javascript macro for copying layers from one Photoshop document to another for anyone familiar with scripting Photoshop. Tried and tested in CS 5.5 on the mac.
sourceDocumentName
, targetDocumentName
and layersToCopy
are the only variables you need to edit to your needs.
On the Mac, you can just save as something like copyLayersBetweenDocs.jsx
, then drag-n-drop the script file on the Photoshop icon in the dock to run. On Windows, you have to save it in the scripts folder C:\Program Files\Common Files\Adobe\Startup Scripts CS5\Adobe Photoshop
and open it from Photoshop
#target photoshop
app.bringToFront();
var sourceDocumentName = 'source-doc';
var targetDocumentName = 'target-doc';
// populate this array with whatever the names of the layers
// you want to copy are
var layersToCopy = new Array(
'road-scenery',
'car',
'wheels',
'front-passenger',
'rear-passenger'
);
// alternatively, specify the name of a layer group containing
// the layers you want to copy over.
// Just uncomment the following line
//var layersToCopy = 'layer-group-to-copy';
copyLayers( layersToCopy, sourceDocumentName, targetDocumentName );
/**
* Copy layer from one document to another
* @param {string|Array} layersToCopy
* @param {string} sourceDocumentName
* @param {string} targetDocumentName
*/
function copyLayers( layersToCopy, sourceDocumentName, targetDocumentName ) {
var
sourceLayer,
targetLayer,
sourceGroup;
var sourceDoc = app.documents[sourceDocumentName];
var targetDoc = app.documents[targetDocumentName];
if ( app.activeDocument != sourceDoc ) {
app.activeDocument = sourceDoc;
}
if ( typeof layersToCopy === 'string' ) {
sourceGroup = sourceDoc.layerSets.getByName( layersToCopy );
targetLayer = sourceGroup.duplicate( targetDoc, ElementPlacement.PLACEATBEGINNING )
}
else if ( Object.prototype.toString.call( layersToCopy ) === '[object Array]' ) {
for ( var i = 0; i < layersToCopy.length; i++ ) {
sourceLayer = sourceDoc.artLayers.getByName( layersToCopy[i] );
targetLayer = sourceLayer.duplicate( targetDoc, ElementPlacement.PLACEATBEGINNING );
}
}
}