Jump to content


Photoshop scripting - how to insert a layer from another PSD

  • Please log in to reply
1 reply to this topic

#1 bzemer


    Young Padawan

  • Members
  • Pip
  • 2 posts

Posted 09 September 2011 - 02:49 AM

I'm fairly new to PS scripting, and I tried my best to do this on my own or find an existing script, but with no luck.

I want to insert a layer (or group) from another PSD file, into the current document. I want to provide the layer/group name and PSD filename in the script itself.

I tried to do this with the script listener plugin, but it just created a script that opens the other PSD.

Is it possible to script this?

Can anyone help and provide a script?


Edited by bzemer, 09 September 2011 - 02:52 AM.

#2 bzemer


    Young Padawan

  • Members
  • Pip
  • 2 posts

Posted 10 September 2011 - 01:24 PM

Got it working with this code:
#target photoshop
function main(){
if(!documents.length) return;
//no documents open 
var originalDoc = activeDocument; 
var origName = decodeURI(activeDocument.name);
var newFile = null;
//select psd file 
while(newFile == null){ newFile =File.openDialog("Please select PSD.","PSD File:*.psd");
} open(newFile);
activeDocument.activeLayer  = activeDocument.layerSets.getByName("*******************replace this with name of required layer ***********************");
alert("Layerset does not exist in this psd");
} dupLayers(origName); app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
} function dupLayers(aDoc) {   function cTID(s) { return app.charIDToTypeID(s);
var desc153 = new ActionDescriptor();
var ref61 = new ActionReference();
ref61.putEnumerated( cTID('Lyr '), cTID('Ordn'), cTID('Trgt') );
desc153.putReference( cTID('null'), ref61 );
var ref62 = new ActionReference();
ref62.putName( cTID('Dcmn'), aDoc ); 
desc153.putReference( cTID('T   '), ref62 );
desc153.putInteger( cTID('Vrsn'), 2 ); 
executeAction( cTID('Dplc'), desc153, DialogModes.NO );

Edited by bzemer, 10 September 2011 - 01:28 PM.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users