• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

946

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

Community Expert , 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; 
...

Votes

Translate

Translate
Adobe
LEGEND ,
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.

Votes

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

Votes

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
LEGEND ,
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.

Votes

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
Community Expert ,
May 24, 2021 May 24, 2021

Copy link to clipboard

Copied

Votes

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

 

 

 

Votes

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

Votes

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