Photoshop: Remove unused layer styles

14 Votes
LEGEND ,
Nov 28, 2011 Nov 28, 2011

Copy link to clipboard

Copied

Feature Request....

Option to remove unused Layer Styles.
Control-click/Right-click the fx icon for a Layer and get...

| Copy Layer Style |
| Paste Layer Style |
| Clear Unused Styles | (NEW)
| Clear Layer Styles |



I spend so much time manually click-dragging empty layer style options to the trash.

Thanks!
Idea No status

Views

455

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
25 Comments
New Here ,
May 03, 2012 May 03, 2012

Copy link to clipboard

Copied

This is exacetly what drives me crazy too!

My suggestion would be to have a button which says: "Consolidate all unused layer styles" which then would remove them. Rather than doing this by hand to many single layers, I think it would be a nice to have on a global scale.

Votes

Translate

Translate

Report

Report
Valorous Hero ,
May 03, 2012 May 03, 2012

Copy link to clipboard

Copied

In the mean time you could try this script...



#target photoshop
app.bringToFront();

app.activeDocument.suspendHistory('Remove Unused FX', 'main()');

function main(){
if(!documents.length) return;
selectAllLayers();
var selLayers = getSelectedLayersIdx();
for(var a in selLayers){
clearUnusedFX(Number(selLayers[a]));
}
}
function clearUnusedFX(idx){
var ref = new ActionReference();
ref.putProperty( charIDToTypeID("Prpr") , stringIDToTypeID( "layerEffects" ));
ref.putIndex( charIDToTypeID( "Lyr " ), idx);
var desc = executeActionGet(ref);
if(desc.hasKey(stringIDToTypeID('layerEffects'))){
makeActiveByIndex( idx );
var FXs = desc.getObjectValue(stringIDToTypeID('layerEffects'));
var ref9 = new ActionReference();
ref9.putProperty( charIDToTypeID("Prpr") , stringIDToTypeID( 'layerFXVisible'));
ref9.putIndex( charIDToTypeID( "Lyr " ), idx);
var vis = executeActionGet(ref9);
var delALL = undefined;
if(vis.hasKey(stringIDToTypeID('layerFXVisible'))) delALL = vis.getBoolean(stringIDToTypeID('layerFXVisible'));
}else{
return;
}
var c = FXs.count;
var Effects= new Array();
for(var i=0;i<c;i++){
Effects.push(typeIDToStringID(FXs.getKey(i)));
}
for(var z in Effects){
if(z == 0) continue;
var bool = FXs.getObjectValue(stringIDToTypeID(Effects[z].toString())).getBoolean (stringIDToTypeID('enabled'));
if(!bool || delALL == false) delFx(Effects[z].toString());
}
function delFx(fx){
var desc147 = new ActionDescriptor();
var ref45 = new ActionReference();
switch(fx.toString()){
case 'dropShadow' : ref45.putClass(charIDToTypeID('DrSh')); break;
case 'innerShadow' : ref45.putClass(charIDToTypeID('IrSh')); break;
case 'outerGlow' : ref45.putClass(charIDToTypeID('OrGl')); break;
case 'innerGlow' : ref45.putClass(charIDToTypeID('IrGl')); break;
case 'bevelEmboss' :ref45.putClass(charIDToTypeID('ebbl')); break;
case 'frameFX' : ref45.putClass(charIDToTypeID('FrFX')); break;
case 'chromeFX' : ref45.putClass(charIDToTypeID('ChFX')); break;
case 'solidFill' : ref45.putClass(charIDToTypeID('SoFi')); break;
case 'gradientFill' : ref45.putClass(charIDToTypeID('GrFl')); break;
case 'patternFill' : ref45.putClass(stringIDToTypeID('patternFill')); break;
default : break;
}
ref45.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
desc147.putReference( charIDToTypeID('null'), ref45 );
try{
executeAction( charIDToTypeID('dsfx'), desc147, DialogModes.NO );
}catch(e){}
}
}
function makeActiveByIndex( idx ){
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putIndex(charIDToTypeID( "Lyr " ), idx)
desc.putReference( charIDToTypeID( "null" ), ref );
desc.putBoolean( charIDToTypeID( "MkVs" ), true );
executeAction( charIDToTypeID( "slct" ), desc, DialogModes.NO );
};
function selectAllLayers() {
var desc29 = new ActionDescriptor();
var ref23 = new ActionReference();
ref23.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
desc29.putReference( charIDToTypeID('null'), ref23 );
executeAction( stringIDToTypeID('selectAllLayers'), desc29, DialogModes.NO );
}
function getSelectedLayersIdx(){
var selectedLayers = new Array;
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var desc = executeActionGet(ref);
if( desc.hasKey( stringIDToTypeID( 'targetLayers' ) ) ){
desc = desc.getList( stringIDToTypeID( 'targetLayers' ));
var c = desc.count
var selectedLayers = new Array();
for(var i=0;i<c;i++){
try{
activeDocument.backgroundLayer;
selectedLayers.push( desc.getReference( i ).getIndex() );
}catch(e){
selectedLayers.push( desc.getReference( i ).getIndex()+1 );
}
}
}else{
var ref = new ActionReference();
ref.putProperty( charIDToTypeID("Prpr") , charIDToTypeID( "ItmI" ));
ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
try{
activeDocument.backgroundLayer;
selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" ))-1);
}catch(e){
selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" )));
}
}
return selectedLayers;
};

Votes

Translate

Translate

Report

Report
LEGEND ,
May 03, 2012 May 03, 2012

Copy link to clipboard

Copied

Thanks Paul. I'll absolutely try it.

Votes

Translate

Translate

Report

Report
New Here ,
May 03, 2012 May 03, 2012

Copy link to clipboard

Copied

Cool! I will defo give it a try!

Votes

Translate

Translate

Report

Report
Adobe Employee ,
May 03, 2012 May 03, 2012

Copy link to clipboard

Copied

In Photoshop CS6 we added Layer Search. Within that you can also search for layers by Attribute (i.e. Find all layers with Attribute Layer Effects or that are invisible). From there you can select the layers and delete them or whatever. One option is to add the ability to search by Attribute: Unused Layer Styles. Then you could select the layers and "Clear Layer Styles". How does that idea resonate?

Votes

Translate

Translate

Report

Report
LEGEND ,
May 03, 2012 May 03, 2012

Copy link to clipboard

Copied

Hi Zorana,

Interesting but the "clear layer styles" command removed all style attributes. What I would like to see is to remove non-visible or hidden attributes.

If I have a layer....


When I copy layers the hidden Effects copy with the layer. While working I may copy a layer many times.

If I attempt to use the new layer search to target layers with the Stroke effect......


The layers don't show because the effect is hidden.

I actually agree with Simon, I'd prefer a global command to remove all hidden layer styles so in one fell swoop I can eliminate all those non-visible style attributes on all layers. The command would be more similar to the Delete Hidden Layers command, but only remove style attributes.

I'd alos like it if when option-dragging to copy Layer Styles between layers, if ONLY the visible style attributes copied, not all attributes.

Votes

Translate

Translate

Report

Report
LEGEND ,
May 03, 2012 May 03, 2012

Copy link to clipboard

Copied

By the way.. wonderful job on CS6.

Votes

Translate

Translate

Report

Report
New Here ,
May 04, 2012 May 04, 2012

Copy link to clipboard

Copied

I have just tried the script Paul has posted earlier. That works well and is all I need.
The only thing which would top it would be an integrated function/button in the layer menu (right click on a layer) similar to what Scott has suggested.

I guess I will build a panel using the Configurator now and integrate the script myself.

Edit: I have built a Configurator panel now which links to the .jsx script in my "../Presets/Scripts" folder (works fine). Can anyone tell me how I could use the script from Paul in Configurator without linking to an external file. Whenever I copy this source code into a script "button" nothing happens... Thanks a ton!

Edit II: After a bit of testing I come to following result: The script works perfect, with one little "imperfection". As far as I understand, it goes through all the layers (no matter whether the layers are hidden or not) checks all the different layer styles and if some of them are unticked, it removes them. But what it also does is it switches hidden layers on to check them and leaves them visible. Which is a problem if you work with layer comps - some of my layers are hidden for a reason and if the script suddenly switches them back on it creates a situation which takes lots of time to fix again. @ Paul - can the script be modified so that this can be avoided (leave the layer visibilty as it was before?)
I would do it myself but I don't understand how to script 😞

Votes

Translate

Translate

Report

Report
Valorous Hero ,
May 04, 2012 May 04, 2012

Copy link to clipboard

Copied

Hi Simon, sorry about that, change the line in the makeActiveByIndex( idx ) function...

From :-
desc.putBoolean( charIDToTypeID( "MkVs" ), true );

To :-
desc.putBoolean( charIDToTypeID( "MkVs" ), false );

That should fix the problem.

Votes

Translate

Translate

Report

Report
LEGEND ,
May 04, 2012 May 04, 2012

Copy link to clipboard

Copied

Paul,

This is excellent. Exactly what I needed. Thank you!

Votes

Translate

Translate

Report

Report
Valorous Hero ,
May 04, 2012 May 04, 2012

Copy link to clipboard

Copied

I hope you have made the above change Scott and glad it works for you.

Simon if you do a lot with Layercomps I have another script that removes layers that are not used in any layercomp, it just cleans the psd. It's here if it's any use to you...
http://www.scriptsrus.talktalk.net/Cl...
Maybe you could add it to your configurator panel.

Votes

Translate

Translate

Report

Report
LEGEND ,
May 04, 2012 May 04, 2012

Copy link to clipboard

Copied

Yes. I made the change before trying it. Works wonderfully, Paul. Thanks again.

Votes

Translate

Translate

Report

Report
New Here ,
May 06, 2012 May 06, 2012

Copy link to clipboard

Copied

Hi to all of you :)

just coming back from a weekend away - so I haven't been able to test the latest changes on the script. Will do it tomorrow.

Paul I am sure it'll work - thanks a lot for your help there!! I will also have a look the 2nd script you've mentioned.

Edit: Btw if someone's keen to install the panel mentioned above, give me a shout.

Votes

Translate

Translate

Report

Report
LEGEND ,
Jul 13, 2012 Jul 13, 2012

Copy link to clipboard

Copied

My suggestion would be to have a global ‘Clear Layer Styles’ option beneath the existing ’Delete Hidden Layers’ entry in the Layers palette fly out menu.

In fact there's a whole host of clean up options that would be very useful: Delete Empty Groups, Delete Empty Layer Masks, Delete Empty Vector Masks, Delete Empty Layers, Delete hidden maks, etc.

On top of this an overall ‘Clean up file’ option could execute all of these commands, reducing a file to its current viewing state.

Votes

Translate

Translate

Report

Report
LEGEND ,
Aug 05, 2013 Aug 05, 2013

Copy link to clipboard

Copied



After working on a document I end up with hundreds of hidden layer effects that were experiments. Just like there's an option to delete all hidden layers, there should be an option to delete all hidden layer effects.

Votes

Translate

Translate

Report

Report
New Here ,
Jul 29, 2015 Jul 29, 2015

Copy link to clipboard

Copied

I receive this error when try to run the script.

Can someone help?

I understand nothing form scripts but this one was very useful for me. Unfortunately it stopped working with the latest version of Photoshop.

Votes

Translate

Translate

Report

Report
LEGEND ,
Oct 06, 2016 Oct 06, 2016

Copy link to clipboard

Copied

Any update to this script? I am getting the same error as the user above. CC 2015.5

Votes

Translate

Translate

Report

Report
Valorous Hero ,
Oct 07, 2016 Oct 07, 2016

Copy link to clipboard

Copied

Sorry I only have CS6 and will not be changing to CC so I will not be updating the script for CC.
You might be able to find someone with CC to debug it and get it working again?

Votes

Translate

Translate

Report

Report
Adobe Community Professional ,
Feb 16, 2017 Feb 16, 2017

Copy link to clipboard

Copied

Votes

Translate

Translate

Report

Report
LEGEND ,
May 21, 2017 May 21, 2017

Copy link to clipboard

Copied

Good news everyone. I created new script which does same job, but it's 10× faster and works from CS6 to CC2017. It also can show progressbar and some statistics what it done.

It is optimized for thousands of layers.

Download here: http://bereza.cz/ps/

Votes

Translate

Translate

Report

Report
LEGEND ,
May 21, 2017 May 21, 2017

Copy link to clipboard

Copied

Update here: http://bereza.cz/ps/

Votes

Translate

Translate

Report

Report
LEGEND ,
May 22, 2017 May 22, 2017

Copy link to clipboard

Copied

Thanks so much. Can't wait to get these working. 

Votes

Translate

Translate

Report

Report
LEGEND ,
May 22, 2017 May 22, 2017

Copy link to clipboard

Copied

I noticed that I had some strangeness in the script. Because since CC2015 layers can have disabled effects even if you can't see them in layers panel. Next version could be a little faster and show the statistics correctly. Anyway, the current version should maintain the appearance of the document as it is.

Votes

Translate

Translate

Report

Report
LEGEND ,
May 22, 2017 May 22, 2017

Copy link to clipboard

Copied

Jeffrey Tranberry: There is bug in Photoshop if you want clear whole layer styles in text layer with scripting. The command "Clear Styles" is not sometimes available and sometimes is. It's like random generator.

Edit: I am using app.doProgress method and clearFx doesn't works if progressbar is shown. And dialog shows after some time period which leads to seemingly  random behavior. Total wasted hours with this bug: ~5 hours

This is second bug I found while I am trying to make this script. First is that you can't remove one certain effect if there is multiple effects of same kind. It always removes first effect of same kind... so I need to set whole style descriptor.

Votes

Translate

Translate

Report

Report
LEGEND ,
Oct 23, 2017 Oct 23, 2017

Copy link to clipboard

Copied

LATEST
we need remove unused layer styles please. it's a basic request. 

Votes

Translate

Translate

Report

Report