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

Script to remove hidden/unused Layer Effects?

Explorer ,
Mar 30, 2018 Mar 30, 2018

Copy link to clipboard

Copied

Does anyone have, or know if it's possible to remove hidden/unused layer effects of selected layer(s) with a script? (Not on every layer in the document, only selected layers)

For example here I'd have to drag each unused effect to the trash can at the bottom

ps remove hidden layer effects.png

Would be great if you could remove the hidden ones while still leaving those that are visible via a script

TOPICS
Actions and scripting

Views

4.9K

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

People's Champ , Apr 02, 2018 Apr 02, 2018

This can be due to layer protection. Try this variant.

var r = new ActionReference();     

r.putProperty(charIDToTypeID("Prpr"), stringIDToTypeID("targetLayers"));  

r.putEnumerated(charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt")); 

 

if (executeActionGet(r).hasKey(stringIDToTypeID("targetLayers"))) 

    { 

    var list = executeActionGet(r).getList(stringIDToTypeID("targetLayers")); 

 

    var offset = 0; 

    try { activeDocument.backgroundLayer } catch (e) { offset = 1;

...

Votes

Translate

Translate
Adobe
Enthusiast ,
Mar 30, 2018 Mar 30, 2018

Copy link to clipboard

Copied

Check my scripts: Magic scripts for Photoshop

I have one for layer effects and one for smart filters. But it is for all layers in document. If you want skip some layers, you can lock 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
Explorer ,
Apr 01, 2018 Apr 01, 2018

Copy link to clipboard

Copied

Thanks, I saw that

But really, I'm looking for a script that runs on the selected layers.

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
Enthusiast ,
Apr 01, 2018 Apr 01, 2018

Copy link to clipboard

Copied

You or somebody else could change my code. But I will not do it.

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
Explorer ,
Apr 01, 2018 Apr 01, 2018

Copy link to clipboard

Copied

Not really the kind of answer I was looking for on a 'help forum', haha.

But thanks, I might try that.

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
New Here ,
Feb 14, 2023 Feb 14, 2023

Copy link to clipboard

Copied

Very useful scripts, thank you, bro!

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
People's Champ ,
Apr 02, 2018 Apr 02, 2018

Copy link to clipboard

Copied

Try

var r = new ActionReference();   

r.putProperty(charIDToTypeID("Prpr"), stringIDToTypeID("targetLayers"));

r.putEnumerated(charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));

if (executeActionGet(r).hasKey(stringIDToTypeID("targetLayers")))

    {

    var list = executeActionGet(r).getList(stringIDToTypeID("targetLayers"));

    var offset = 0;

    try { activeDocument.backgroundLayer } catch (e) { offset = 1; }

    for (var n = 0; n < list.count; n++)

        {

        var idx = list.getReference(n).getIndex();

        var r = new ActionReference();   

        r.putProperty(charIDToTypeID("Prpr"), stringIDToTypeID("layerEffects"));

        r.putIndex(charIDToTypeID("Lyr "), idx+offset);

        if (!executeActionGet(r).hasKey(stringIDToTypeID("layerEffects"))) continue;

        var d = executeActionGet(r).getObjectValue(stringIDToTypeID("layerEffects"));

        for (var i = 0; i < d.count; i++)

            {

            var key = d.getKey(i);

            var type = d.getType(key);

   

            if (type == DescValueType.OBJECTTYPE)

                {

                var enabled = d.getObjectValue(key).getBoolean(stringIDToTypeID("enabled"));

   

                if (!enabled)

                    {

                    var d2 = new ActionDescriptor();

                    var r = new ActionReference();

                    r.putClass(d.getClass(key));

                    r.putIndex(charIDToTypeID("Lyr "), idx + offset);

                    d2.putReference(stringIDToTypeID("null"), r);

                    executeAction(stringIDToTypeID("disableSingleFX"), d2, DialogModes.NO);

                    }

       

                }

            }

        }

    }

else

    {

    alert("no selected layers")

    }

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
Explorer ,
Apr 02, 2018 Apr 02, 2018

Copy link to clipboard

Copied

Thanks! I've tried it, but get the following error message:

- The command "Delete Layer Style" is not currently available.

Line: 40

->

executeAction(stringIDToTypeID("disableSinfleFX"),d2,DialogModes.NO);

Any idea how to fix that?

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
People's Champ ,
Apr 02, 2018 Apr 02, 2018

Copy link to clipboard

Copied

This can be due to layer protection. Try this variant.

var r = new ActionReference();     

r.putProperty(charIDToTypeID("Prpr"), stringIDToTypeID("targetLayers"));  

r.putEnumerated(charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt")); 

 

if (executeActionGet(r).hasKey(stringIDToTypeID("targetLayers"))) 

    { 

    var list = executeActionGet(r).getList(stringIDToTypeID("targetLayers")); 

 

    var offset = 0; 

    try { activeDocument.backgroundLayer } catch (e) { offset = 1; } 

    var unlock_flag = false;

    var lock = false;

    var del_cnt = 0;

 

    for (var n = 0; n < list.count; n++) 

        { 

        var idx = list.getReference(n).getIndex(); 

 

        var r = new ActionReference();     

        r.putProperty(charIDToTypeID("Prpr"), stringIDToTypeID("layerEffects"));  

        r.putIndex(charIDToTypeID("Lyr "), idx+offset); 

 

        if (!executeActionGet(r).hasKey(stringIDToTypeID("layerEffects"))) continue; 

 

        var d = executeActionGet(r).getObjectValue(stringIDToTypeID("layerEffects")); 

        var r = new ActionReference();     

        r.putProperty(charIDToTypeID("Prpr"), stringIDToTypeID("layerLocking"));  

        r.putIndex(charIDToTypeID("Lyr "), idx+offset); 

        if (!unlock_flag) lock = executeActionGet(r).getObjectValue(stringIDToTypeID("layerLocking")).getBoolean(stringIDToTypeID("protectAll"));

        for (var i = 0; i < d.count; i++) 

            { 

            var key = d.getKey(i); 

            var type = d.getType(key); 

     

            if (type == DescValueType.OBJECTTYPE) 

                { 

                var enabled = d.getObjectValue(key).getBoolean(stringIDToTypeID("enabled")); 

     

                if (!enabled) 

                    { 

                    if (lock && !unlock_flag)

                        {

                        var d2 = new ActionDescriptor();

                        var d1 = new ActionDescriptor();

                        var d3 = new ActionDescriptor();

                        var r = new ActionReference();

                        r.putIndex(charIDToTypeID("Lyr "), idx+offset); 

                        d1.putReference( charIDToTypeID( "null" ), r );

                        d3.putBoolean( stringIDToTypeID( "protectAll" ), false);

                        d2.putObject( stringIDToTypeID( "layerLocking" ), stringIDToTypeID( "layerLocking" ), d3 );

           

                        d1.putObject( charIDToTypeID( "T   " ), charIDToTypeID( "Lyr " ), d2 );

                        executeAction( charIDToTypeID( "setd" ), d1, DialogModes.NO );

                        unlock_flag = true;

                        }

                    var d2 = new ActionDescriptor(); 

                    var r = new ActionReference(); 

                    r.putClass(d.getClass(key)); 

                    r.putIndex(charIDToTypeID("Lyr "), idx + offset); 

                    d2.putReference(stringIDToTypeID("null"), r); 

                    executeAction(stringIDToTypeID("disableSingleFX"), d2, DialogModes.NO); 

                    ++del_cnt;

                    } 

         

                } 

            } 

        } 

    alert(del_cnt + " LayerEffects have been removed"); 

    } 

else 

    { 

    alert("no selected layers") 

    } 

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
Explorer ,
Apr 02, 2018 Apr 02, 2018

Copy link to clipboard

Copied

Perfect, thanks a lot!

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
Explorer ,
May 03, 2023 May 03, 2023

Copy link to clipboard

Copied

LATEST

we made a Photoshop plug-in that can do this. The unlimited version is 12$. 

02D36B26-2826-4A93-A672-9F8CA982A903.png

 

Full Version (12$):
https://exchange.adobe.com/apps/cc/c36e02fb/swift


Trial Version (Limited to 5 Actions):
https://exchange.adobe.com/apps/cc/412c1dcd/swift-trial-version

 

Its also a big help with getting the layers selected.

ACDB94BA-0EEB-49C2-9175-058DE034925B.png

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