This example script will take a directory of input files and run the UnSharpMask filter with a range (start/end or "edge"/step) for amount, radius and threshold.
I'm trying to figure out how to have multiple "if else" statements change data in an Array while looping through the script. Say I already have a set ballpark minimum and maximum from some combinations of amount, radius and threshold that I want hold to. I get the idea of what I am trying to do, but when I attempt to put it into practice I am doing probably doing something very simple incorrect. Script below with question in bold red:
#target photoshop
function SaveTIFF(saveFile){
tiffSaveOptions = new TiffSaveOptions();
tiffSaveOptions.embedColorProfile = true;
tiffSaveOptions.alphaChannels = true;
tiffSaveOptions.layers = true;
tiffSaveOptions.imageCompression = TIFFEncoding.TIFFLZW;
activeDocument.saveAs(saveFile, tiffSaveOptions, true, Extension.LOWERCASE);
};
function range(start, edge, step) {
if (arguments.length == 01) {
edge = start;
start = 00;
}
edge = edge || 00;
step = step || 01;
for (var ret = []; (edge - start) * step > 00; start += step) {
ret.push(start);
}
return ret;
}
function main() {
var Base = Folder.selectDialog("Select directory to process");
var BaseFiles = Base.getFiles("*.psd");
var errorlog = File(Base + "/Test_Log.txt");
var d =new Date;
errorlog.open('a');
errorlog.writeln(d);
for (var x = 0 ;x < BaseFiles.length; x++) {
var doc1 = app.open(BaseFiles[x]);
app.activeDocument = doc1;
var filter = "UnSharpMask";
amount = range (50, 501, 50);
radius = range (0, 61, 20);
threshold = range (0, 256, 60);
for (var i = 0; i < amount.length; i ++) {
for (var j = 0; j < radius.length; j ++) {
for (var k = 0; k < threshold.length; k ++) {
// if (amount >200){ I want to be able either change the entire radius start/edge/step range or just change the radius start = 10; and then say Threshold start = 60;}
// else if (amount <200 && amount >100) change radius and threshold
// else if (amount <100) change radius and threshold
activeDocument.activeLayer.applyUnSharpMask(amount[i],radius[j],threshold[k]);
var doc = BaseFiles[x];
var Path = File(Folder.desktop);
var Name = doc.name.replace(/\.[^\.]+$/, '');
var saveFile = File(Path + "/UnSharpMask/" + Name + "_" + filter + "_amount" + amount[i] + "_radius" + radius[j] +"_threshold" + threshold[k] + ".tif");
SaveTIFF(saveFile);
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
app.open(BaseFiles[x]);
}
}
}
while (documents.length > 0) {
activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}
}
}
main();