我的文件太多了,所以我尝试在Windows 7 pro x64上的Adobe Photoshop CC 2014中使用*.jsx
脚本文件删除所有文本图层。
我在互联网上找到了这部分代码,当我编辑时,我收到了错误。
// test 1
#target photoshop
var myLayers = app.activeDocument.layers.everyItem().getElements();
for(var i=myLayers.length-1;i=0;i--){
if(myLayers[i].LayerKind.TEXT){
myLayers[i].remove();
continue;
}
}
// test 2
var theLayers = collectEmptyGroups(app.activeDocument, []);
//alert (theLayers.join("\n"));
for (var x = 0; x < theLayers.length; x++) {
try {theLayers[x].remove()}
catch (e) {}};
////// function collect all layers //////
function collectEmptyGroups (theParent, allLayers) {
if (!allLayers) {var allLayers = new Array}
else {};
var theNumber = theParent.layers.length - 1;
for (var m = theNumber; m >= 0;m--) {
var theLayer = theParent.layers[m];
// apply the function to layersets;
if (theLayer.typename == LayerKind.TEXT) {
// allLayers.push(theLayer)
}
else {
allLayers = (collectEmptyGroups(theLayer, allLayers))
// this line includes the empty layer groups;
if (theLayer.layers.length == 0) {allLayers.push(theLayer)}
}
};
return allLayers
};
你能帮助我吗?
答案 0 :(得分:3)
您发布的代码看起来并不干净,而且很难分清哪些错误。
这是一种非常简单的方法(在Win 10 x64上使用Photoshop CS6进行测试):
function findLayersText (layers) {
for (var i = 0, len = layers.length; i < len; i++) {
if (layers[i].kind == "LayerKind.TEXT") {
layers[i].remove();
len--;
}
}
}
//check all art layers then
//check if there are any inner layer sets
function browseLayerSets (sets) {
for (var i = 0, len = sets.length; i < len; i++) {
findLayersText(sets[i].artLayers);
if(sets[i].layerSets.length > 0){
browseLayerSets(sets[i].layerSets);
}
}
}
//check all root art layers for text layer
findLayersText(app.activeDocument.artLayers);
//browse all root layer sets (if any)
browseLayerSets(app.activeDocument.layerSets);