0 Replies Latest reply on Oct 23, 2011 7:31 PM by Dan Rodney

    [JS] Items on page vs pasteboard move differently in CS3 vs CS4/CS5

    Dan Rodney Adobe Community Professional

      I'm trying to move all the items on all the pages in a document (including the master pages), regardless of what layer they are on and I want to retain their locked/unlocked states. In trying to figure this out I came across Adobe's AdjustLayout Sample script. This was quite helpful and I adapted it to move all the items a specified amount (the modified script is shown below). There may be a better way, but this was pretty much working.

       

      Except one problem:

      - In CS4 and later all items move, those on or off the page (in the pasteboard).

      - In CS3 though, only the items on a page move, and NOT the ones on the pasteboard (which I do also want to move).

       

      I have searched this forum and read a lot, but still haven't figured out how to get CS3 to also move the pasteboard items. Can anyone help? Below is the script I adapted, but I am open to other ways if there's something better. I used this because it seemed close to what I was looking for.

       

      Thanks, in advance.

      Dan

       

       

      //Moves the content by specified amounts 
      //based on sample script by Adobe, but this moves objects by same amount regardless of even or odd pages
      
      myDisplayDialog();
      
      
      function myDisplayDialog(){
                var myLabelWidth = 70;
                var myDialog = app.dialogs.add({name:"Adjust Layout"});
                with(myDialog.dialogColumns.add()){
                          with(borderPanels.add()){
                                    with(dialogRows.add()){
                                              with(dialogColumns.add()){
                                                        staticTexts.add({staticLabel:"Offset Amount:", minWidth:myLabelWidth});
                                                        staticTexts.add({staticLabel:"Horizontal:", minWidth:myLabelWidth});
                                                        staticTexts.add({staticLabel:"Vertical:", minWidth:myLabelWidth});
                                              }
                                              with(dialogColumns.add()){
                                                        staticTexts.add({staticLabel:""});
                                                        var myXField = measurementEditboxes.add({editValue:-12, editUnits:MeasurementUnits.points});
                                                        var myYField = measurementEditboxes.add({editValue:0, editUnits:MeasurementUnits.points});
                                              }
                                    }
                          }
                }
                var myResult = myDialog.show();
                if(myResult == true){
                          var myX = myXField.editValue;
                          var myY = myYField.editValue;
                          myDialog.destroy();
                          myAdjustPages(myX, myY);
                }
                else{
                          myDialog.destroy();
                }
      }
      
      
      function myAdjustPages(myX, myY){
                var myPage;
          //Set the transform content property to true so that content will move with frames.
          //myOldTransformContent = app.transformPreferences.transformContent;
          //app.transformPreferences.transformContent = true;
          var usersXUnits = app.activeDocument.viewPreferences.horizontalMeasurementUnits;
          var usersYUnits = app.activeDocument.viewPreferences.verticalMeasurementUnits;
          //Set the measurement units to points.
          app.activeDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.points;
          app.activeDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.points;
          //Save the old page numbering
          var myOldPageNumbering = app.generalPreferences.pageNumbering;
          app.generalPreferences.pageNumbering = PageNumberingOptions.section;
          //Set page numbering to absolute
          app.generalPreferences.pageNumbering = PageNumberingOptions.absolute;
          for(var myCounter = 0; myCounter < app.activeDocument.pages.length; myCounter++){
              myPage = app.activeDocument.pages.item(myCounter);
              var myPageValue = myPage.documentOffset;
              myAdjustPage(myPage, myX, myY);
          }
          for(var myMasterPageCounter = 0; myMasterPageCounter < app.activeDocument.masterSpreads.length; myMasterPageCounter++){
              myMasterPage = app.activeDocument.masterSpreads[myMasterPageCounter].pages[0];
              var myPageValue = myMasterPage.documentOffset;
              myAdjustPage(myMasterPage, myX, myY);
          }    //Reset the transform content and measurement units to their original values.
          app.activeDocument.viewPreferences.horizontalMeasurementUnits = usersXUnits;
          app.activeDocument.viewPreferences.verticalMeasurementUnits = usersYUnits;
          //app.transformPreferences.transformContent = myOldTransformContent;
          app.generalPreferences.pageNumbering = myOldPageNumbering;
      }
      
      
      function myAdjustPage(myPage, myX, myY){
                var myPageItem;
                for(var myCounter = 0; myCounter < myPage.pageItems.length; myCounter ++){
                          var myResetItemLock = false;
                          var myResetLayerLock = false;
                          myPageItem = myPage.pageItems.item(myCounter);
                          if(myPageItem.locked == true){
                                    myPageItem.locked = false;
                                    myResetItemLock = true;
                          }
                          if(myPageItem.itemLayer.locked == true){
                                    myPageItem.itemLayer.locked = false;
                                    myResetLayerLock = true;
                          }
                          myPageItem.move(undefined, [myX, myY]);
                          if(myResetItemLock == true){
                                    myPageItem.locked = true;
                          }
                          if(myResetLayerLock == true){
                                    myPageItem.itemLayer.locked = true;
                          }
                }
      }