6 Replies Latest reply on Feb 16, 2017 2:30 AM by Heimdaal

    Various inconsistencies when detecting layer effects

    Heimdaal Level 1

      I've read this thread on checking for layer effects using ActionManager code: How to get the style of a  layer using photoshop scripting ??

       

      And I'm using the below code to try and check for the bevel and emboss effect:

      // Checks for bevel and emboss effect
      function sTID(s){ return app.stringIDToTypeID(s); };
      
      
      var ref = new ActionReference();  
      ref.putEnumerated(sTID("layer"), sTID("ordinal"), sTID("targetEnum") );   
      res = executeActionGet(ref).getObjectValue(sTID("layerEffects")).hasKey(sTID("bevelEmboss"));
      
      
      alert(res); 
      

       

      But the problem here is that it returns true for ALL layer effects. Why?

      I'm using the below code to check for the stroke FX and it works as expected - but as you can see, changing the TypeID in the hasKey() -function doesn't seem to be working.

       

      // Checks for stroke effect
      function sTID(s){ return app.stringIDToTypeID(s); };
      
      
      var ref = new ActionReference();  
      ref.putEnumerated(sTID("layer"), sTID("ordinal"), sTID("targetEnum") );   
      res = executeActionGet(ref).getObjectValue(sTID("layerEffects")).hasKey(sTID("frameFX"));
      
      
      alert(res);
      

       

      Another inconsistency is that if you have multiple effects, the layer effect is sometimes not found at all - unless you manually go into the effects options and chose "delete hidden effects". You can try this with the following code for instance:

      
      // Checks for the drop shadow effect
      function sTID(s){ return app.stringIDToTypeID(s); };
      
      
      var ref = new ActionReference();  
      ref.putEnumerated(sTID("layer"), sTID("ordinal"), sTID("targetEnum") );   
      res = executeActionGet(ref).getObjectValue(sTID("layerEffects")).hasKey(sTID("dropShadow"));
      
      
      alert(res); 
      
      
        • 1. Re: Various inconsistencies when detecting layer effects
          SuperMerlin Level 5

          // Checks for bevel and emboss effect function

          function sTID(s){ return app.stringIDToTypeID(s); };  

          var ref = new ActionReference();  

          ref.putEnumerated(sTID("layer"), sTID("ordinal"), sTID("targetEnum") );   

          var desc = executeActionGet(ref).getObjectValue(sTID("layerEffects"));

          if(desc.hasKey(sTID("bevelEmboss"))){ 

          alert("Has bevelEmboss"); 

          }else{

              alert("does not have bevelEmboss");

              }

          • 2. Re: Various inconsistencies when detecting layer effects
            Heimdaal Level 1

            That is the same code that I use and I get false-positives with it

             

            Update to original post:
            Checking for layer effects breaks when there are two of the same layer effects active. Most likely a key error.
            Bevel and Emboss is broken - It gives false positives all the time.

            Satin is also broken - Like Bevel and Emboss it also gives false positives all the time.

            • 3. Re: Various inconsistencies when detecting layer effects
              SuperMerlin Level 5

              Might be down to the Photoshop version? CS6 is ok.

              • 4. Re: Various inconsistencies when detecting layer effects
                Heimdaal Level 1

                Possibly. I'm on CC 2017 right now.

                • 5. Re: Various inconsistencies when detecting layer effects
                  Heimdaal Level 1

                  Another update:

                  The keys for each layer effect change when there are multiple effects of the same kind. Example:
                  Say that you have one inner shadow effect. Then the key is "innerShadow". But if you have 0 or 2+ innerShadow effects then the key is "innerShadowMulti". This can be confirmed with this code:

                   

                  function sTID(s){ return app.stringIDToTypeID(s); };
                  
                  
                  var ref = new ActionReference();  
                  ref.putEnumerated(sTID("layer"), sTID("ordinal"), sTID("targetEnum") );   
                  result = executeActionGet(ref).getObjectValue(sTID("layerEffects")).getKey(2);
                  result = typeIDToStringID(result);
                  alert(result);
                  

                   

                  Now run that code in jsh on a layer with 0, 1 and 2 Inner Shadow -effects. You will get "innerShadow" when there is only 1 effect of this kind, but "innerShadowMulti" when there is 0 or 2+ effects. I've found that the reason for this behavior is different from the Satin and Bevel&Emboss -FX is that in the case of the latter two, there can only be one of a kind on a layer. In other words: a layer can have multiple drop shadow FX, but only one Bevel&Emboss. My conclusion is that in order to determine the status of all layer effects, we have to go deeper into the object.

                  • 6. Re: Various inconsistencies when detecting layer effects
                    Heimdaal Level 1

                    I have also discovered that once you apply a layer effect to a layer, the following keys are added to the layer effects -descriptor:

                    bevelEmboss

                    chromeFX

                     

                    ...and this happens even if you DON'T add these effects to the layer and even if you DO "delete hidden effects".

                    In other words: you have to go deeper into the object and actually have a look at the attributes -_- Why Adobe, WHY?