根据ID选中多个图层 (如果删除了图层导致某些ID不存在呢)
例如:选中ID为2,5,6图层
var ids=new Array;
ids.push(2);
ids.push(5);
ids.push(6);
multiSelectByIDs(ids);
function doesIdExists( id ){// function to check if the id exists
var res = true;
var ref = new ActionReference();
ref.putIdentifier(charIDToTypeID('Lyr '), id);
try{var desc = executeActionGet(ref)}catch(err){res = false};
return res;
}
function multiSelectByIDs(ids) {
if( ids.constructor != Array ) ids = [ ids ];
var layers = new Array();
var id54 = charIDToTypeID( "slct" );
var desc12 = new ActionDescriptor();
var id55 = charIDToTypeID( "null" );
var ref9 = new ActionReference();
for (var i = 0; i < ids.length; i++) {
if(doesIdExists(ids[i]) == true){// a check to see if the id stil exists
layers[i] = charIDToTypeID( "Lyr " );
ref9.putIdentifier(layers[i], ids[i]);
}
}
desc12

这篇博客介绍了一个JavaScript函数,用于在Adobe Photoshop中根据给定的ID批量选择图层。首先,定义了一个`doesIdExists`函数来检查ID对应的图层是否存在。然后,`multiSelectByIDs`函数遍历ID数组,调用`doesIdExists`检查并创建ActionReference以选中存在的图层。这个功能对于自动化图层操作非常有用。
最低0.47元/天 解锁文章
1204

被折叠的 条评论
为什么被折叠?



