Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Why duplicating activeDocument before calling saveAs() ?

Guest
Aug 11, 2013 Aug 11, 2013

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?

TOPICS
Actions and scripting
884
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Guru ,
Aug 11, 2013 Aug 11, 2013

My guess is the script could have been written to save without the dupe step. But the script does change the document and I think the dupe just makes it easier to deal with those changes. That is it doesn't have to restore the changes after saving each comp.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 11, 2013 Aug 11, 2013

I see. So if I understand correctly it's a safety measure?

My intention is to drop it, since this code affects the user: additional document is opening & then closing in the photoshop main screen UI. Something that the user might see when running the script.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Aug 11, 2013 Aug 11, 2013

If you are talking about this specific script it is more than a safety measure. It is more of a way to handle changes the script makes to the document.

I wouldn't drop duping the document unless code was added to to restore the document to the state it was in at the script's startup.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 12, 2013 Aug 12, 2013

I'm talking about the script that I'm writing, and using that script as learning base.

Thanks for all the help.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Mar 28, 2014 Mar 28, 2014
LATEST

I realize this is a very old post... found it while looking for something else.

The document must be duplicated because the "File Save" operation would rename the CURRENT document and that's probably not desired.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines