1 Reply Latest reply on Sep 10, 2014 9:24 PM by JJMack

    return the height of a selection using photoshop javascript??

    filterFactor

      So i am working on a script.

       

      I need to know the height of a selection I create using the magicWand via scriptlistener code

       

      The closest I can get is using the "doc.recordMeasurements( MeasurementSource.MEASURESELECTION, undefined);"

       

      that calls up the measurement analysis which will list the height of the selection. but i cant seem to pull the data out

       

      do i need to create a list and array to get that data into a variable?

        • 1. Re: return the height of a selection using photoshop javascript??
          JJMack Most Valuable Participant

          There is a scripting forum Photoshop Scripting

           

          // enable double-clicking from Mac Finder or Windows Explorer

          #target photoshop // this command only works in Photoshop CS2 and higher

           

          // bring application forward for double-click events

          app.bringToFront();

           

          // Save the current preferences

          var startRulerUnits = app.preferences.rulerUnits;

          // Set Photoshop to use pixels

          app.preferences.rulerUnits = Units.PIXELS;

           

          if (hasSelection()) {

            makeLayer(); // Make Temp Work Layer

            app.activeDocument.selection.fill(app.foregroundColor);

            var LB = activeDocument.activeLayer.bounds;

            var LWidth = (LB[2].value) - (LB[0].value);

            var LHeight = (LB[3].value) - (LB[1].value);

            activeDocument.activeLayer.remove();

            alert("Width = " +  LWidth + "px     Height = " + LHeight +"px" + "\nTop Left " +  LB[0].value + "," +  LB[1].value + "  Bottom Right "  +  LB[2].value + "," +  LB[3].value  );

            }

          else alert("There is no Active Selection");

          // Return the app preferences

          app.preferences.rulerUnits = startRulerUnits;

           

          ////// check for seelction //////

          function hasSelection(){

          var ref = new ActionReference();

          ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );

          var docDesc = executeActionGet(ref);

          var hasSelection = docDesc.hasKey(stringIDToTypeID("selection"));

          return hasSelection;

          };

           

          function makeLayer(){

            var idMk = charIDToTypeID( "Mk  " );

               var desc4 = new ActionDescriptor();

               var idnull = charIDToTypeID( "null" );

                   var ref3 = new ActionReference();

                   var idLyr = charIDToTypeID( "Lyr " );

                   ref3.putClass( idLyr );

               desc4.putReference( idnull, ref3 );

            executeAction( idMk, desc4, DialogModes.NO );

          }