2 Replies Latest reply on Feb 16, 2010 10:54 PM by psm3d

    How to know whether a selection area has pixels or not?

    psm3d

      Hi all,

      I want to know how to know whether a selection area has pixels or not ( empty) using the javascript.

      can anyone help me?

        • 1. Re: How to know whether a selection area has pixels or not?
          Paul Riggott Level 6

          Using Mike's function you can do this...

          main();
          function main(){
          var doc = activeDocument;
          if(hasSelection (doc)){
          var result = interscetTransparency();
          if(result && !hasSelection (doc)){
              alert("No pixels exist");
              }else{
                  alert("Pixels exist");
                  }
              }
          }
          
          function interscetTransparency() {
              var desc = new ActionDescriptor();
                  var channelRef = new ActionReference();
                  channelRef.putEnumerated( charIDToTypeID('Chnl'), charIDToTypeID('Chnl'), charIDToTypeID('Trsp') );
              desc.putReference( charIDToTypeID('null'), channelRef );
                  var selectionRef = new ActionReference();
                  selectionRef.putProperty( charIDToTypeID('Chnl'), charIDToTypeID('fsel') );
              desc.putReference( charIDToTypeID('With'), selectionRef );
              try{
              executeAction( charIDToTypeID('Intr'), desc, DialogModes.NO );
              return true;
              }catch(e){return false;}
          };
          function hasSelection (doc) { 
            var res = false; 
            var as = doc.activeHistoryState; 
            doc.selection.deselect(); 
            if (as != doc.activeHistoryState) { 
              res = true; 
              doc.activeHistoryState = as; 
            } 
            return res; 
          };
          
          • 2. Re: How to know whether a selection area has pixels or not?
            psm3d Level 1

            Thank you very much Paul and Mike

            It is working!