Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


Delete level based on first name

Advocate ,
May 24, 2021 May 24, 2021

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

Schermata 2021-05-24 alle 11.56.02.png

 

This is what I have now

app.activeDocument.layers.getByName("test").remove();

TOPICS
Actions and scripting

Views

717

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Adobe Community Professional , May 24, 2021 May 24, 2021
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; ...

Likes

Translate

Translate
Adobe Community Professional ,
May 24, 2021 May 24, 2021

Copy link to clipboard

Copied

Make a loop to take into account all 'levels' that starts with 'test' word.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
May 24, 2021 May 24, 2021

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
May 24, 2021 May 24, 2021

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.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
May 24, 2021 May 24, 2021

Copy link to clipboard

Copied

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
May 24, 2021 May 24, 2021

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()");

 

 

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
May 25, 2021 May 25, 2021

Copy link to clipboard

Copied

LATEST

Thank you all

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines