Exclude entering non positive integers and Exit scripts under specific conditions
Hi,
I have the following script. I want to exclude all input non positive integers. When the input is not a positive integer, stop the script from executing the following code. Can someone help me? Thank you in advance!
function highlightLayerInContainer (targetLayer) {
var someTempPath = targetLayer.pathItems.rectangle(0, 0, 200, 200);
someTempPath.name = "TEMP [for highlighting]";
app.activeDocument.selection = null;
someTempPath.selected = true;
app.doScript("target layer", "Test Set 2");
someTempPath.remove();
}
var dupN=prompt("Please enter the number of layers to copy:","8","Tips");
if (dupN!=null && dupN!="") // I want to exclude all non positive integers entered, but I don't know how to write these conditions??
{
for (var i=1;i<dupN;i++) {
highlightLayerInContainer(app.activeDocument.layers[0].layers[0]);
app.doScript("DupeLayer", "Test Set 2");
app.activeDocument.layers[0].layers[0].name=i+1
}
}
else
{
alert("Please do not press the \"Cancel\" button!!\n\nPlease rerun the script and enter the number of layers to copy!!");
// If the input is not a positive integer, I want to stop the script here and stop executing the following code. If I use 'Return', I will be prompted with an error ??
}
var doc = app.activeDocument;
var layers = doc.layers;
for (var i = doc.layers.length - 1; i > -1; i--) {
recursiveRename(doc.layers[i]);
}
function recursiveRename(parent) {
for (var i = 0; i < parent.layers.length; i++) {
parent.layers[i].name = parent.layers[i].name.replace(/_复制.*$/, "");
recursiveRename(parent.layers[i]);
}
}
