This is an old problem we met with dropdown lists with all Visual languages (Visual Basic, Delphi, etc.).
When you want to delete items in a combo or list, you must do it from the last item to the first.
Same thing with layers. You must begin to delete from background to the upper layer. If you begin at 0, it will not work because each time a layer is deleted the order of following layers changes. Hoping you will understand my English.
Try this :
Code: Select all
var docRef = app.activeDocument
var layers = docRef.artLayers;
var nbrLayers = layers.length-1;
while (nbrLayers >-1) {
var str = layers[nbrLayers].name.search("abc");
if (str >-1) {
docRef.activeLayer = layers.getByName(layers[nbrLayers].name);
docRef.activeLayer.remove();
}
nbrLayers-=1;
}