extendscript - 使用 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,"");
}
解决方案
您想要的正确布尔测试是
if (selectedLayers[i] instanceof TextLayer) {
instanceof
, 没有引号TextLayer
。
推荐阅读
- mysql - mysql显示所有列,但某些列是唯一的
- sql-server - 是否需要按时间间隔在 MS sql 服务器上重建非聚集索引
- python-2.7 - Stanford ner tagger 区分大小写
- c# - 我可以在 C# 中声明命名的异步元组函数吗?
- c# - x 数组中的重复元素添加到 y 数组中
- c# - 删除没有值的ddl
- c# - ValueObject 应该由类内部的静态方法合并还是由 util 类合并?使用 C# 和 DDD
- google-apps-script - 谷歌网站脚本api给出空值
- sql - 子查询返回超过 1 个值 - MS SQL
- c# - asp.net 应用程序中的级联下拉列表方法错误 500