Script (JS) : Loading file directly to a layer
Hi all,
In my script, I load files to process them one by one. The script is like :
// folder selection
sourceFolder = Folder.selectDialog("Please select your source files directory");
sourceFilesList = sourceFolder.getFiles(/\.(jpg|png|tif|jpeg)$/i);
numFiles = sourceFilesList.length;
sourceFilesList.sort();
// error checks
// (...)
// load dimensions and resulotion of the files in the folder
// (they all have the same characteristics)
var sourceDoc = app.open(sourceFilesList[0]);
sourceDocWidth = sourceDoc.width;
sourceDocHeight = sourceDoc.height;
resolution = sourceDoc.resolution;
// create the result image
resultDoc = app.documents.add(sourceDocWidth, sourceDocHeight, resolution, et_resultFile.text);
for (var i = 0; i < numFiles; i++) {
// load image file
var sourceDoc = app.open(sourceFilesList[i]);
// copy and paste the image to a layer in the result file
sourceDoc.selection.selectAll();
sourceDoc.selection.copy();
app.activeDocument = resultDoc;
resultDoc.paste();
sourceDoc.close(SaveOptions.DONOTSAVECHANGES);
// now do something with the layer in the result file
layer = resultDoc.activeLayer;
// (...code here...)
} // end for i loopYou see that I load a file, then select it all, copy and paste in the work (result) file, then close the source file. It takes quite some time to do this and I can't find a way to open directly the source file in a new layer in the result file without copy/paste.
Any idea ?
Fred
