2 Replies Latest reply on Jan 14, 2011 11:11 AM by dayglowdave

    A bug? Or have I not declared something correctly

    dayglowdave

      In this script I wrote, the idea was for a user to enter the height and width (in pixels) of an image and how many times they want it tiled up and down. When they run the script it should lay out guide lines as specified, when I hard code values it works great but when I try to use the gui to do the same thing it places all the guidelines at 0.0 . any thoughts?

       

       

       

       

      var myWindow = new Window('dialog', 'Set Image Parameters');

        

      //-----INPUT 

          myWindow.add('statictext',undefined,"Image Width:");

          var myEditX = myWindow.add('edittext', undefined, '0');

              myEditX.characters = 30;

              myEditX.active = true;

          myWindow.add('statictext',undefined,"Image Height:");

          var myEditY = myWindow.add('edittext', undefined, '0');

              myEditY.characters = 30;

          myWindow.add('statictext', undefined, '# Across');

          var numAcross = myWindow.add('edittext', undefined, '0');

              numAcross.characters = 30;

          
          myWindow.add('statictext', undefined, '# Down');

          var numDown = myWindow.add('edittext', undefined, '0');

              numDown.characters = 30;



      //-----BUTTONS    

          var ok_button = myWindow.add('button', undefined, 'Ok');
          
      //--BEGIN BUTTON ON CLICK EVENT--//


          ok_button.onClick = function(){

              var picX = myEditX.text;
              var picY = myEditY.text;
              var picW = numAcross.text;
              var picH = numDown.text;
               var docW = picW*picX;
               var docH = picH*picY;
          //myWindow.close();
              
      // Create new document in photoshop



              var newDocumentRef = app.documents.add(docW,docH,72.0);
              preferences.rulerUnits = Units.PIXELS;

      //end document creation

      //declare offset variables

              var currentOffset = 0;
              var offsetValue = picX; 
              var currentOffsetB = 0;         
              var offsetValueB = picY;         

      //iterate through loops and add guide lines to the active document in photoshop; the bug is in here somewhere

              for(i=0; i<picW; i++){   

                  app.activeDocument.guides.add(Direction.VERTICAL, currentOffset);

                  currentOffset = currentOffset + offsetValue;
                             
              }

              for(j=0; j<picH; j++){

                  app.activeDocument.guides.add(Direction.HORIZONTAL, currentOffsetB);

                  currentOffsetB = currentOffsetB + offsetValueB;

              }
                      

          };

      //--END BUTTON ON CLICK EVENT--//

      myWindow.show();