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
Would be great if you could remove the hidden ones while still leaving those that are visible via a script
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;
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.
Copy link to clipboard
Copied
Thanks, I saw that
But really, I'm looking for a script that runs on the selected layers.
Copy link to clipboard
Copied
You or somebody else could change my code. But I will not do it.
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.
Copy link to clipboard
Copied
Very useful scripts, thank you, bro!
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")
}
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?
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")
}
Copy link to clipboard
Copied
Perfect, thanks a lot!