1 Reply Latest reply on Jun 14, 2017 7:21 AM by JJMack

    Does .duplicate() copy element to a new document?

    i73 Level 1

      I am looking at the 'Export Layers To Files.jsx' to convert the parts of the exportChildren to C++ for my plugin, I need to know does .duplicate() duplicate a Element to a new document (does it copy the element, create a new doc, and paste it)?


      function exportChildren(dupObj, orgObj, exportInfo, dupDocRef, fileNamePrefix) {

          for( var i = 0; i < dupObj.artLayers.length; i++) {

              if (exportInfo.visibleOnly) { // visible layer only

                  if (!orgObj.artLayers[i].visible) {




              dupObj.artLayers[i].visible = true;



              var layerName = dupObj.artLayers[i].name;  // store layer name before change doc

              var duppedDocumentTmp = dupDocRef.duplicate();

              if ((psdIndex == exportInfo.fileType)||(png24Index == exportInfo.fileType)||(png8Index == exportInfo.fileType)) { // PSD: Keep transparency


        • 1. Re: Does .duplicate() copy element to a new document?
          JJMack Most Valuable Participant

          Perhaps! In that script it would depend on what "dupDocRef" is.   There are many duplicate methods in  Adobe Photoshop's Scripting DOM.


          Method    Paramaters                             Parameter type                     Returns           What it does
          duplicate([relativeObject][, insertionLocation]) ArtLayer|LayerSet,ElementPlacement ArtLayer|LayerSet Creates a duplicate of the object .
          duplicate([targetDocument])                      Document                           Channel           Duplicates the channel.
          duplicate([name ][, mergeLayersOnly])            string,boolean                     Document          Creates a duplicate of the document object.
          duplicate([relativeObject][, insertionLocation]) ArtLayer|LayerSet,ElementPlacement LayerSet          Creates a duplicate of the object.
          duplicate(name)                                  string                                               Duplicates pathItem object with the new name.


          Look like it is method 4 the way it is coded so yes it creates a new document in Photoshop and returns the document object in the variable  duppedDocumentTmp

          It look line method 4 because of the variable name used by the coder implies a document object is expected to be returned.


          Then all the invisible layer in the duplicated document are then removed by the script in this new document.