8 Replies Latest reply on Apr 2, 2018 10:56 AM by jonohunt

    Script to remove hidden/unused Layer Effects?

    jonohunt Level 1

      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

        • 1. Re: Script to remove hidden/unused Layer Effects?
          Jarda Bereza Level 4

          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.

          1 person found this helpful
          • 2. Re: Script to remove hidden/unused Layer Effects?
            jonohunt Level 1

            Thanks, I saw that

             

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

            • 3. Re: Script to remove hidden/unused Layer Effects?
              Jarda Bereza Level 4

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

              • 4. Re: Script to remove hidden/unused Layer Effects?
                jonohunt Level 1

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

                 

                But thanks, I might try that.

                • 5. Re: Script to remove hidden/unused Layer Effects?
                  r-bin Level 4

                  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")
                      }
                  
                  1 person found this helpful
                  • 6. Re: Script to remove hidden/unused Layer Effects?
                    jonohunt Level 1

                    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?

                    • 7. Re: Script to remove hidden/unused Layer Effects?
                      r-bin Level 4

                      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")  
                          }  
                      
                      1 person found this helpful
                      • 8. Re: Script to remove hidden/unused Layer Effects?
                        jonohunt Level 1

                        Perfect, thanks a lot!