delete all layers including "abc"
delete all layers including "abc"
I am working on a photoshop sclipt.
in the layer name
I want to delete all layers including "abc".
for (d=1; d < 37 ; ) {
LayerName = "abc"+ d
RemoveLayers(LayerName);
d++;
}
function RemoveLayers(LayerName){
for(var i = 0; i < 15 ; ){
var Layers = documents[0].artLayers;
if (Layers[0].name == LayerName) {
Layers[0].remove();
}
i++;
}
}
- Attachments
-
- abc.jpg (86.2 KiB) Viewed 6835 times
Last edited by lee ky on Tue Mar 03, 2020 4:53 am, edited 4 times in total.
Re: delete all layers including "abc"
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 :
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;
}
Re: delete all layers including "abc"
I tried what you said with ExtendScript DropDownList and found I don't have to delete them from last item (but selected one):
Code: Select all
win = new Window('dialog')
lst = win.add('dropdownlist', [0, 0, 100, 20], [1, 2, 3])
btn = win.add('button', undefined, 'Delete an item')
btn.onClick = function() {lst.remove(lst.selection)} win.show()
Re: delete all layers including "abc"
I there is the following items in a dropdown list
- layer dfr
- layer dabc
- layer 123
- layer ght
- layer abc
how do you delete the two items in which the word "abc" is present ? I am not sure to have understood the method.
- layer dfr
- layer dabc
- layer 123
- layer ght
- layer abc
how do you delete the two items in which the word "abc" is present ? I am not sure to have understood the method.
Re: delete all layers including "abc"
This refers to sole dropdownlist, so without connection to document layers.
Re: delete all layers including "abc"
Thank you very much.
Thanks to that, it was solved.
Thanks to that, it was solved.
Re: delete all layers including "abc"
Ok, I understand. Thank you.