4 Replies Latest reply on Nov 13, 2010 6:23 PM by colegaMiCoche

    Selection does not properly snap to script-added guides

    colegaMiCoche Level 1

      Hi there, this is the first time trying to write a script for Photoshop. I'm trying to create a script that, given a document, adds two vertical guides so the separation between them is 960px and it's centered in the document.

       

      This is what I got so far:

       

      preferences.rulerUnits = Units.PIXELS;


      if(app.documents.length != 0){

          if(activeDocument.width > 960){

              var x1 = Math.round((activeDocument.width - 960) / 2);

              var x2 = x1 + 960;

             

              activeDocument.guides.add(Direction.VERTICAL, x1);

              activeDocument.guides.add(Direction.VERTICAL, x2);

              alert("Guides added at x1=" + x1 + " and x2=" + x2);

          }else{

              alert("Your document needs to be wider than 960px");

          }

      }else{

          alert("No document active");

      }

       

      The guides are placed properly, it's a really simple script anyways. The problem is that, whenever I try to make a selection from the left guide to the right one (in order to get a 960px-width rectangle, for instance), the selection always snap 1px to the left of the left guide, so the selection is 961px. If I make the selection from the right guide to the left, there's no problem. Also, If I place the guides by hand, there's no problem either.

       

      It's really driving me mad! What is the problem?