我的功能是检查某个artlayer在所有RGB通道中是否具有所有值为0的像素。我在此类artlayer属性的文档(Photoshop CS6 Scripting Guide,Photoshop CS6 JavaScript Ref)中找不到任何信息。
------------------------------------------------ ---------------------------编辑
var docRef = app.activeDocument;
var layerRef = docRef.artLayers.add();
docRef.selection.selectAll();
docRef.selection.fill(app.foregroundColor);
layerRef.kind = LayerKind.TEXT;
if (layerRef.kind === LayerKind.TEXT) {
alert("layer is empty");
}
在Photoshop-CS6-JavaScript-Ref.pdf中写道:“注意:您只能从一个空的艺术层创建文本层”。因此,我想使用poperty layerKind.TEXT检查layer是否为空,但取而代之的是,我只收到了错误通知:这是我认为可行的唯一解决方案。
我仅需要检查artlayer bounds
的属性以找出其数组的所有值是否均等于"0 px"
。当它们全部为"0 px"
时,则表示该层为空。在下面,我创建了一个函数来检查输入层是否为空。
#target photoshop
var doc = app.activeDocument;
var certainLayer = doc.artLayers[0];
var isLayerEmpty = isLayerEmptyCheck(certainLayer);
alert(isLayerEmpty);
function isLayerEmptyCheck(layer) {
var isLayerEmpty = new Boolean;
var LayerBounds = layer.bounds;
if (LayerBounds[0] === "0 px" && LayerBounds[1] === "0 px" && LayerBounds[2] === "0 px" && LayerBounds[3] === "0 px") {
return isLayerEmpty = true;
} else {
return isLayerEmpty = false;
}
}