如果没有选择图像的任何部分,如何中止脚本?Photoshop Javascript



如果没有选择图像的任何部分,如何中止脚本?Photoshop Javascript

我只需要一个命令作为脚本运行的先决条件,只需检查是否有选择,如果没有选择,则中止脚本。

您的问题在这里基本上得到了回答,可能并不明显。

您可以使用app.activeDocument.selection.bounds检查选择

把它变成一个功能是你需要的:

// create a variable to hold the outcome of the selection (true/false)
var mySelection = is_selection_active();
Display the results of the function
alert(mySelection);
function is_selection_active()
{
// use try/catch just in case
try
{
// selectbounds is the four points of the largest area of the selection
// top, left, bottom, right (if memory serves)
var selectbounds = app.activeDocument.selection.bounds;
// display the selection bounds co-ordinates
alert(selectbounds);
// if there's a selection return true
return true;
}
catch(e)
{
// No selection?? Return false
return false;
}
}
}

最新更新