Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
I'm talking about the script that I'm writing, and using that script as learning base.
Thanks for all the help.
Copy link to clipboard
Copied
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.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now