Copy link to clipboard
Copied
Good morning
I would like to delete the level with initial test name
however the level has the name test v1
v1 is not to be taken into account
must delete the level based on the test name only.
This is what the level looks like
This is what I have now
app.activeDocument.layers.getByName("test").remove();
I modified another script into something that works for me, perhaps it will work for you too:
/*
Delete level based on first name
https://community.adobe.com/t5/photoshop/delete-level-based-on-first-name/td-p/12062329
*/
#target photoshop
function main() {
// Call the function to process layers/layerSets
processLayersAndSets(app.activeDocument);
function processLayersAndSets(target) {
// Loop through all layers
for (var l = target.artLayers.length - 1; 0 <= l;
...
Copy link to clipboard
Copied
Make a loop to take into account all 'levels' that starts with 'test' word.
Copy link to clipboard
Copied
Kukurykus
You are always kind in wanting to help me
I honestly don't know where to start
a small string of code would be useful
thanks again for your help
Copy link to clipboard
Copied
Are you serious? After so many years getting experience and samples from this forum and using much more advanced codes you are asking for one of most simplest thing to do, so making loop over layers? There are plenty threads showing how to do it - browse them.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
I modified another script into something that works for me, perhaps it will work for you too:
/*
Delete level based on first name
https://community.adobe.com/t5/photoshop/delete-level-based-on-first-name/td-p/12062329
*/
#target photoshop
function main() {
// Call the function to process layers/layerSets
processLayersAndSets(app.activeDocument);
function processLayersAndSets(target) {
// Loop through all layers
for (var l = target.artLayers.length - 1; 0 <= l; l--) {
// Call the removeLayer function
removeLayer(target.artLayers[l]);
}
// Loop through all layer groups/sets
for (var s = target.layerSets.length - 1; 0 <= s; s--) {
// Call the removeLayer function
processLayersAndSets(target.layerSets[s]);
}
// Remove non-background layers beginning with the word "test", case insensitive
function removeLayer(layer) {
if (!layer.isBackgroundLayer & layer.name.match(/^test\b/i) !== null) layer.remove();
}
}
}
app.activeDocument.suspendHistory("Run script", "main()");
Copy link to clipboard
Copied
Thank you all