首页 > 解决方案 > 使用 selectedLayers 属性过滤文本图层

问题描述

我正在尝试检查图层的类型,以确保我的函数调用仅适用于选定图层中的文本图层(选定图层的数量为数百)。看来我使用 typeOf 方法犯了一些错误。有人可以帮忙吗?

var myComp = app.project.activeItem;
var selectedLayers = myComp.selectedLayers;
var numLayers = selectedLayers.length;

    for(var i=0; i < numLayers; i++){
        var mySourceText = selectedLayers[i].property("ADBE Text Properties").property("ADBE Text Document");
        var myTextDoc = mySourceText.value;
             if (typeOf(selectedLayers[i]) == "TextLayer") {
                mySourceText.setValue(trim(myTextDoc));
            }
     }

function trim(strValue){
    var str = new String(strValue);
    return str.replace(/(^\s*)|(\s*$)/g,"");
}

标签: extendscript

解决方案


您想要的正确布尔测试是

if (selectedLayers[i] instanceof TextLayer) {

instanceof, 没有引号TextLayer


推荐阅读