如何在 Photoshop 脚本中抑制弹出消息 "No pixels are selected."
how to suppress pop-up message in Photoshop script "No pixels are selected."
我有一个脚本可以遍历文档并检查每一层是否有空白图层蒙版,然后删除该图层蒙版。
我不确定是否有比获取选区并反转它更好的方法来检查图层蒙版是否为空白。
反转后,如果没有选区,Photoshop会弹出警告信息"No pixels are selected."
如何在不检查的情况下避免出现此消息 "Don't show again"?
for ( var a =0; a<activeDocument.artLayers.length; a++ ){
activeDocument.activeLayer = activeDocument.artLayers[a];
checkLayerMask();
};
function checkLayerMask() {
// has layer mask
var ref = new ActionReference();
ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
var desc = executeActionGet(ref);
var hasLayerMask = desc.hasKey(charIDToTypeID("UsrM")); // bool
if (hasLayerMask) {
// make layer mask active
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID( "Chnl" ), charIDToTypeID( "Chnl" ), charIDToTypeID( "Msk " ) );
desc.putReference( charIDToTypeID( "null" ), ref );
desc.putBoolean( charIDToTypeID( "MkVs" ), false );
executeAction( charIDToTypeID( "slct" ), desc, DialogModes.NO );
// get selection from layer mask
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putProperty( charIDToTypeID( "Chnl" ), charIDToTypeID( "fsel" ) );
desc.putReference( charIDToTypeID( "null" ), ref );
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID( "Chnl" ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );
desc.putReference( charIDToTypeID( "T " ), ref );
executeAction( charIDToTypeID( "setd" ), desc, DialogModes.NO );
// invert selection
activeDocument.selection.invert();
try { activeDocument.selection.bounds}
catch(e) {
// delete active layer mask
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID( "Chnl" ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );
desc.putReference( charIDToTypeID( "null" ), ref );
executeAction( charIDToTypeID( "Dlt " ), desc, DialogModes.NO );
};
}
app.activeDocument.selection.deselect();
};
将 DialogModes
设置为 NO
的 AM 命令不会生成此消息:
executeAction(charIDToTypeID('Invs'), undefined, DialogModes.NO);
我有一个脚本可以遍历文档并检查每一层是否有空白图层蒙版,然后删除该图层蒙版。
我不确定是否有比获取选区并反转它更好的方法来检查图层蒙版是否为空白。
反转后,如果没有选区,Photoshop会弹出警告信息"No pixels are selected."
如何在不检查的情况下避免出现此消息 "Don't show again"?
for ( var a =0; a<activeDocument.artLayers.length; a++ ){
activeDocument.activeLayer = activeDocument.artLayers[a];
checkLayerMask();
};
function checkLayerMask() {
// has layer mask
var ref = new ActionReference();
ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
var desc = executeActionGet(ref);
var hasLayerMask = desc.hasKey(charIDToTypeID("UsrM")); // bool
if (hasLayerMask) {
// make layer mask active
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID( "Chnl" ), charIDToTypeID( "Chnl" ), charIDToTypeID( "Msk " ) );
desc.putReference( charIDToTypeID( "null" ), ref );
desc.putBoolean( charIDToTypeID( "MkVs" ), false );
executeAction( charIDToTypeID( "slct" ), desc, DialogModes.NO );
// get selection from layer mask
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putProperty( charIDToTypeID( "Chnl" ), charIDToTypeID( "fsel" ) );
desc.putReference( charIDToTypeID( "null" ), ref );
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID( "Chnl" ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );
desc.putReference( charIDToTypeID( "T " ), ref );
executeAction( charIDToTypeID( "setd" ), desc, DialogModes.NO );
// invert selection
activeDocument.selection.invert();
try { activeDocument.selection.bounds}
catch(e) {
// delete active layer mask
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID( "Chnl" ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );
desc.putReference( charIDToTypeID( "null" ), ref );
executeAction( charIDToTypeID( "Dlt " ), desc, DialogModes.NO );
};
}
app.activeDocument.selection.deselect();
};
将 DialogModes
设置为 NO
的 AM 命令不会生成此消息:
executeAction(charIDToTypeID('Invs'), undefined, DialogModes.NO);