1 PSD process completes but multiple jpg files open continuously. 2 PSD open but JPG not open
First PSD File open ans process completes but multiple jpg files open continuously. second process PSD File open but JPG File not open error this Line var jpgDoc = open(jpgFile);
1) Input Psd folder contains many psd files already.
All layers of Input Psd file are already renamed to HFrame and VFrame.
2) Input jpg folder already contains many jpg files.
The number of jpg files can be unlimited
2) outputPSDFolder
(Problem 1. )
A first psd file is opened from the input psd to run the script.
Then jpg are opened one by one from the input jpg folder and
clipping is done in HFrame and VFrame layers.
Work has been completed on all layers.
But jpg file should be stopped open,
psd should be saved.
But all the jpg files of the folder continue to open and do not stop.
After all the jpg files are opened, the psd file is saved in the output.
(Problem 2. )
After the first psd file process is complete,
the psd file is saved and after the next psd file is opened,
the jpg file is not opened.
// Input PSD file select folder dialog
var inputPSDFolder = Folder.selectDialog("Select the folder containing PSD files");
// Input JPG file select folder dialog
var inputJPGFolder = Folder.selectDialog("Select the folder containing JPG files");
// Output PSD file select folder dialog
var outputPSDFolder = Folder.selectDialog("Select the folder to save the processed PSD files");
// Process PSD and JPG files
processPSDAndJPGFiles(inputPSDFolder, inputJPGFolder, outputPSDFolder);
function processPSDAndJPGFiles(inputPSDFolder, inputJPGFolder, outputPSDFolder) {
var psdFiles = getFilesInFolder(inputPSDFolder, "psd");
var jpgFiles = getFilesInFolder(inputJPGFolder, "jpg");
for (var i = 0; i < psdFiles.length; i++) {
var psdFile = psdFiles[i];
// Open the PSD file
var doc = open(psdFile);
for (var j = 0; j < jpgFiles.length; j++) {
var jpgFile = jpgFiles[j];
// Open the JPG file as a separate document
var jpgDoc = open(jpgFile);
var layerName = "";
var isHorizontal = false;
// Determine the layer name based on the orientation of the JPG file
if (jpgDoc.height > jpgDoc.width) {
layerName = "VFrame";
isHorizontal = false;
} else {
layerName = "HFrame";
isHorizontal = true;
}
// Switch to the PSD document
// Check if the PSD document has the target layer
var hasTargetLayer = hasLayer(doc, layerName);
if (hasTargetLayer) {
// Perform actions when the layer exists
app.activeDocument = jpgDoc;
jpgDoc.selection.selectAll();
jpgDoc.selection.copy();
// Close the JPG document
var startDisplayDialogs = app.displayDialogs;
app.displayDialogs = DialogModes.NO;
var savedRuler = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
Folder((fnp = (fle = (jpgDoc = activeDocument).fullName).parent + '/FINISH/')).create();
jpgDoc.saveAs(File(fnp + jpgDoc.name), new JPEGSaveOptions(JPEGSaveOptions.quality = 12));
jpgDoc.close(SaveOptions.DONOTSAVECHANGES);
File(fle).remove();
app.activeDocument = doc;
var ref = new ActionReference();
ref.putName(stringIDToTypeID('layer'), layerName);
var desc = new ActionDescriptor();
desc.putReference(stringIDToTypeID('null'), ref);
executeAction(stringIDToTypeID('select'), desc, DialogModes.NO);
// Rename the selected layer
var newName = "MM Ravi";
activeDocument.activeLayer.name = newName;
// Create a new layer and paste the contents
var newLayer = doc.paste();
// Rest of the code...
// Group the new layer
var groupRef = new ActionReference();
groupRef.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
var groupDesc = new ActionDescriptor();
groupDesc.putReference(charIDToTypeID("null"), groupRef);
executeAction(charIDToTypeID("GrpL"), groupDesc, DialogModes.NO);
var oldPref = app.preferences.rulerUnits
////////////////////////////////////////////////////////////////////////////////////////////
var oldPref = app.preferences.rulerUnits
app.preferences.rulerUnits = Units.PIXELS;
var doc = activeDocument;
var iLayer = doc.activeLayer;
layerDown ();
var mLayerB = doc.activeLayer.bounds;
doc.activeLayer = iLayer;
var scale = Math.max((mLayerB[2]-mLayerB[0])/(iLayer.bounds[2]-iLayer.bounds[0]),(mLayerB[3]-mLayerB[1])/(iLayer.bounds[3]-iLayer.bounds[1]));
iLayer.resize (scale*100,scale*100);
iLayer.translate((mLayerB[0]+mLayerB[2])/2-(iLayer.bounds[0]+iLayer.bounds[2])/2,(mLayerB[1]+mLayerB[3])/2-(iLayer.bounds[1]+iLayer.bounds[3])/2);
function layerDown(){
var idslct = charIDToTypeID( "slct" );
var desc2 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref1 = new ActionReference();
var idLyr = charIDToTypeID( "Lyr " );
var idOrdn = charIDToTypeID( "Ordn" );
var idBckw = charIDToTypeID( "Bckw" );
ref1.putEnumerated( idLyr, idOrdn, idBckw );
desc2.putReference( idnull, ref1 );
var idMkVs = charIDToTypeID( "MkVs" );
desc2.putBoolean( idMkVs, false );
var idLyrI = charIDToTypeID( "LyrI" );
var list1 = new ActionList();
list1.putInteger( 3 );
desc2.putList( idLyrI, list1 );
executeAction( idslct, desc2, DialogModes.NO );
};
} else {
// Perform actions when the layer does not exist
// Close the JPG document
jpgDoc.close(SaveOptions.DONOTSAVECHANGES);
}
}
// Save the processed PSD file
doc.saveAs(new File(outputPSDFolder + "/" + psdFile.name));
doc.close(SaveOptions.DONOTSAVECHANGES);
}
}
function getFilesInFolder(folderPath, fileExtension) {
var folder = new Folder(folderPath);
var files = folder.getFiles();
var filteredFiles = [];
for (var i = 0; i < files.length; i++) {
var file = files[i];
if (file instanceof File && getFileExtension(file.name) === fileExtension) {
filteredFiles.push(file);
}
}
return filteredFiles;
}
function getFileExtension(fileName) {
var parts = fileName.split(".");
if (parts.length > 1) {
return parts[parts.length - 1];
}
return "";
}
function hasLayer(doc, layerName) {
var layers = doc.layers;
for (var i = 0; i < layers.length; i++) {
if (layers[i].name === layerName) {
return true;
}
}
return false;
}