Skip to main content
Participant
February 22, 2016
Question

duplicate layer into new document with layer name

  • February 22, 2016
  • 1 reply
  • 518 views

Hello all!

I'm trying to find a script that can duplicate a layer into a new document with the layer name as the new document file name. I can barely eek my way through code so I'm hoping someone here can provide a script solution.

I did find a similar post that provided the following:

function newDocFromLayer(docName,layerName){ 

     docName == undefined ? docName = "Untitled":docName; 

     layerName == undefined ? layerName = activeDocument.activeLayer.name:layerName; 

    var desc = new ActionDescriptor(); 

        var ref = new ActionReference(); 

        ref.putClass( charIDToTypeID( "Dcmn" ) ); 

    desc.putReference( charIDToTypeID( "null" ), ref ); 

    desc.putString( charIDToTypeID( "Nm  " ), docName ); 

         var ref1 = new ActionReference(); 

        ref1.putEnumerated( charIDToTypeID( "Lyr " ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) ); 

    desc.putReference( charIDToTypeID( "Usng" ), ref1 ); 

    desc.putString( charIDToTypeID( "LyrN" ), layerName ); 

executeAction( charIDToTypeID( "Mk  " ), desc, DialogModes.NO ); 

};

I saved this out of extendscript and ran it and nothing happens. I thought possibly because it was for an older version of Photoshop?

Thanks a billion to anyone that can read this and figure out the correct solution.

This topic has been closed for replies.

1 reply

SuperMerlin
Inspiring
February 22, 2016

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

};