5 Replies Latest reply on Mar 28, 2014 10:44 AM by NightSkyGuy

    Why duplicating activeDocument before calling saveAs() ?

    Maxim Veksler

      Reading the scripts supplied with photoshop CS6, namly "Layer Comps To Files.jsx", the save functionality is implemented as following quoted below. I'm wondering why do the script needs to duplicate the activeDocument?

       

       

      // Copyright 2007.  Adobe Systems, Incorporated.  All rights reserved.

       

                  for ( compsIndex = 0; compsIndex < compsCount; compsIndex++ ) {

                      var compRef = docRef.layerComps[ compsIndex ];

                      if (exportInfo.selectionOnly && !compRef.selected) continue; // selected only

                      compRef.apply();

                      var duppedDocument = app.activeDocument.duplicate();

                      var fileNameBody = exportInfo.fileNamePrefix;

       

       

                      fileNameBody += compRef.name;

                      if (null != compRef.comment) fileNameBody += "_" + compRef.comment;

                      fileNameBody = fileNameBody.replace(/[:\/\\*\?\"\<\>\|\\\r\\\n]/g, "_"); // '/\:*?"<>|\r\n' -> '_'

                      if (fileNameBody.length > 120) fileNameBody = fileNameBody.substring(0,120);

                      saveFile(duppedDocument, fileNameBody, exportInfo);

                      duppedDocument.close(SaveOptions.DONOTSAVECHANGES);

                  }

       

       

                function saveFile( docRef, fileNameBody, exportInfo) {

                     // ...

                     docRef.saveAs(saveFile, jpgSaveOptions, true, Extension.LOWERCASE);

                     // ...

                }

       

       

       

      What effects of calling saveAs on the active document has for the user?