Inilah makro wajib Javascript saya untuk menyalin lapisan dari satu dokumen Photoshop ke yang lain untuk siapa pun yang akrab dengan scripting Photoshop. Dicoba dan diuji dalam CS 5.5 pada mac.
sourceDocumentName
, targetDocumentName
dan layersToCopy
merupakan satu-satunya variabel yang perlu diedit sesuai kebutuhan Anda.
Di Mac, Anda bisa menyimpannya seperti copyLayersBetweenDocs.jsx
, lalu seret-n-jatuhkan file skrip pada ikon Photoshop di dock untuk dijalankan. Di Windows, Anda harus menyimpannya di folder skrip C:\Program Files\Common Files\Adobe\Startup Scripts CS5\Adobe Photoshop
dan membukanya dari 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 );
}
}
}