3 Replies Latest reply on Jul 28, 2012 3:06 PM by Paul Riggott

    Is this possible to draw square selection between two Guides...?

    yajiv_viki Level 2

      Hi Everyone,

       

      Is this possible to draw square selection between two Guides. Guides are either Top & Bottom (or) Left & Right.

       

      The rectangle was 200 X 200 fixed ratio. Thanks in advance.

       

      1.jpg

       

      -yajiv

        • 1. Re: Is this possible to draw square selection between two Guides...?
          Paul Riggott Level 6

          This requires Photoshop CS5 or better...

           

           

          #target photoshop
          app.bringToFront();
          main();
          function main(){
          if(app.version.match(/\d+/) < 12) return;
          if(!documents.length) return;
          var doc = activeDocument;
          var guides = doc.guides;
          if(guides.length != 2) return;
          if(guides[0].direction != guides[1].direction) return;
          var startRulerUnits = preferences.rulerUnits;
          preferences.rulerUnits = Units.PIXELS;
          var SB = new Array();
          if(guides[0].direction == Direction.HORIZONTAL && guides[1].direction == Direction.HORIZONTAL){
          var vertDistance = doc.guides[1].coordinate.value - doc.guides[0].coordinate.value;
          SB[0] = (doc.width.value - vertDistance)/2;
          SB[1] = doc.guides[0].coordinate.value;
          SB[2] =  ((doc.width.value - vertDistance)/2)+vertDistance;
          SB[3] = doc.guides[1].coordinate.value;
              }
          if(guides[0].direction == Direction.VERTICAL && guides[1].direction == Direction.VERTICAL){
          var horzDistance = doc.guides[1].coordinate.value - doc.guides[0].coordinate.value;
          SB[0] = doc.guides[0].coordinate.value;
          SB[1] = (doc.height - horzDistance)/2;
          SB[2] = doc.guides[1].coordinate.value;
          SB[3] = ((doc.height - horzDistance)/2)+horzDistance;
              }
          activeDocument.selection.select([[SB[0],SB[1]],[SB[2],SB[1]],[SB[2],SB[3]],[SB[0],SB[3]]], SelectionType.REPLACE, 0, false); 
          app.preferences.rulerUnits = startRulerUnits;
          }
          
          
           
          • 2. Re: Is this possible to draw square selection between two Guides...?
            yajiv_viki Level 2

            Many Thanks Paul Riggott!!!

             

            Thanks for your help. Much appreciated.

             

            If this possible, move selection to center of product.

             

            - yajiv

            • 3. Re: Is this possible to draw square selection between two Guides...?
              Paul Riggott Level 6

              There is no way of knowing where the product is, so all I could do was center the selection.