是否可以检查某些图层是否为空? CS6脚本

问题描述 投票:-2回答:1

我的功能是检查某个artlayer在所有RGB通道中是否具有所有值为0的像素。我在此类artlayer属性的文档(Photoshop CS6 Scripting GuidePhotoshop 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是否为空,但取而代之的是,我只收到了错误通知:enter image description here这是我认为可行的唯一解决方案。

javascript photoshop photoshop-script
1个回答
0
投票

我仅需要检查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;
    }

}
© www.soinside.com 2019 - 2024. All rights reserved.