4 Replies Latest reply on Oct 29, 2010 7:42 AM by [Jongware]

    Script to nudge all items on every page

    JossHarris

      I am quite new to scripting but I am trying to write a script to select all items on every page and them nudge them by specified X and Y values. The script does work but only seems to move 1 item on every page, I know it's probably something really straightforward and I was wondering if anyone on here could point me in the right direction?

        • 1. Re: Script to nudge all items on every page
          JossHarris Level 1

          / check they have a document open


          if (app.documents.length == 0)
          {
              alert ("You must have a document open to run this script");
              exit();
              }
          var myPages = app.activeDocument.pages.length;

           

          // Create User Dialog //
          var myDialog=app.dialogs.add({name:"Enter Nudge Amounts", canCancel:true});

           

          with(myDialog){
              //add a dialog column
              with(dialogColumns.add()){
                  staticTexts.add({staticLabel:"X Nudge"});
                          //create a number (real) entry field
                  var myXoffsetField=realEditboxes.add();
                  }
              }
          with(myDialog){
                  //add a dialog column
              with(dialogColumns.add()){
                  staticTexts.add({staticLabel:"Y Nudge"});
                          //create a number (real) entry field
                  var myYoffsetField=realEditboxes.add();
                  }
              }
          //display the dialog box//
          var myResult=myDialog.show();
          if (myResult==true){
              //get the values from the dialog box controls//
              var myXoffset=myXoffsetField.editValue;
              var myYoffset=myYoffsetField.editValue;

           

              //remove the dialog box from memory//
              myDialog.destroy();
              }

           

          // Create page position co-ordinates //
          var positions =  [myXoffset, myYoffset];
          // loop to nudge images

           

          for (a = myPages-1; a>=0; a--)
          {
          app.activeDocument.pages[a].pageItems.everyItem().select();
          app.selection[0].move (null, positions)
             
          }
          • 2. Re: Script to nudge all items on every page
            Haakenlid Level 3

            There's a sample script called AdjustLayout.jsx in your Application/Samples/JavaScript folder that does pretty much the same thing.

            1 person found this helpful
            • 3. Re: Script to nudge all items on every page
              [Jongware] Most Valuable Participant

              This causes it:

               

              for (a = myPages-1; a>=0; 
              a--)
              {
              app.activeDocument.pages[a].pageItems.everyItem().select();
              app.selection[0].move (null, positions)    
              }
              
              

               

              You are 'selecting' objects but only moving the first one ...

              Under normal circumstances you don't have to use 'select' in a script -- you can "target" any object immediately. And even if you had something selected, all of the objects will still move around! Change it to this, I didn't try but it ought to make it work:

               

              for (a=myPages-1; a>=0; a--)
              {
                app.activeDocument.pages[a].pageItems.everyItem().move (null, positions);
              }
              
              • 4. Re: Script to nudge all items on every page
                JossHarris Level 1

                Thanks very much guys , I knew it was something simple!