3 Replies Latest reply on Jun 25, 2015 7:16 PM by Math Kay

    Script for Increasing or decreasing page width

    Math Kay Level 1

      After the dialog open, based on selected value UI dialog box, there should be modification in indesign document. I want to move further. Please suggest me the script.

       

       

       

      var myDialog = app.dialogs.add({name:"Adjusting Page Width",
      canCancel:true});
      with(myDialog){
      //Add a dialog column.
      with(dialogColumns.add()){
          with(borderPanels.add()){
      var myRadioButtonGroup=radiobuttonGroups.add();
      with(myRadioButtonGroup){
          var myNewmyPageButton=radiobuttonControls.add({staticLabel:"New Page", checkedState:true});
          var myNewRectoButton=radiobuttonControls.add({staticLabel:"New Recto"});
           var myChapterRunInButton=radiobuttonControls.add({staticLabel:"Chapter Run-in"});
           }
       }
       with(borderPanels.add()){
           with(dialogColumns.add()){ 
               staticTexts.add({staticLabel: "Text width Increase by:"});
               }
           with(dialogColumns.add()){
               var myPagewidthIncrease=dropdowns.add({stringList:["0 pt", "3 pt", "6 pt", "9 pt", "12 pt"], selectedIndex:0})
               }
           }
           
      with(borderPanels.add()){
           with(dialogColumns.add()){ 
               staticTexts.add({staticLabel: "Text width Decrease by:"});
               }
           with(dialogColumns.add()){
               var myPagewidthIncrease=dropdowns.add({stringList:["0 pt", "3 pt", "6 pt", "9 pt", "12 pt"], selectedIndex:0})
               }
           }
       }
      }
      //Performing tasks for column values
      varmyresult=myDialog.show();
                
      
      
      
      
      
      
        • 1. Re: Script for Increasing or decreasing page width
          Math Kay Level 1

          For increasing or decreasing the page width, there should be change in only Outside margin.

          • 2. Re: Script for Increasing or decreasing page width
            S Hopkins Adobe Community Professional

            Hi,

             

            Thanks for clarifying that the change should be to the Outside margin. You can change the size of individual pages within a document, so this left me to question if this is what you really wanted.

             

            I revised your script to only show the part of the dialog that deals with the size change. I included this to suggest that in giving a user an option in a dialog that you don't allow conflicting options (both increase and decrease size). That can be confusing. You will see what I mean in running the script. Also be sure that script interaction level is set to interact with all. Notice that the script changes interaction level back to what it was before running the script, and that the dialog is destroyed whether the user cancels or not.

             

            Hope this helps,

             

            var mySizeStrList= ["0 pt", "3 pt", "6 pt", "9 pt", "12 pt"];

            var mySizeList = [0.0, 3.0, 6.0, 9.0, 12.0];

            try {

               var docRef = app.documents.item(0);

               var outsideMarginChange = dialogWMeasure ("Adjusting Page Margins");

               var insideMarginChange = 0.0;

               //define page to change here

               var pageRef = docRef.pages.item(0);

               changePagemargins (pageRef, outsideMarginChange)

            } catch (e) {

               alert (e);

            }

             

             

            function dialogWMeasure (dlgName) {

               var origLevel = app.scriptPreferences.userInteractionLevel;

                app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;

                var myDialog = app.dialogs.add({name:dlgName,  canCancel:true}); 

                with(myDialog){  

                with(dialogColumns.add()){

                 with(borderPanels.add()){ 

                    with(dialogColumns.add()){  

                        staticTexts.add({staticLabel: "Text width change by:"}); 

                        var myRadioButtonGroup=radiobuttonGroups.add(); 

                        with(myRadioButtonGroup){ 

                            var changeSizePositive=radiobuttonControls.add({staticLabel:"Increase Size", checkedState:true}); 

                            var changeSizeNegative=radiobuttonControls.add({staticLabel:"Decrease Size"}); 

                        } 

                     }  

                     with(dialogColumns.add()){ 

                        var pageWidField=dropdowns.add({stringList:mySizeStrList, selectedIndex:0});

                     }

                  } 

                }

            }

            var userCancelled = true;

            if (myDialog.show() == true ){

                userCancelled = false;

                var myButtonChoice = myRadioButtonGroup.selectedButton;

                var myPagewidthChange = mySizeList[pageWidField.selectedIndex];

                if (myButtonChoice == 1) {

                    myPagewidthChange = (myPagewidthChange * -1.0)

                 }

            }

            app.scriptPreferences.userInteractionLevel = origLevel;

            myDialog.destroy();

            if (userCancelled) { 

                 throw ("User cancelled");

            } else {

                return  myPagewidthChange;

            }

            }

             

            /*Right margin is outside margin if facing pages*/

            function changePagemargins (pageRef, outsideMarginChange) {

                   var myRightMargin = pageRef.marginPreferences.right;

                   var myOutsideMargin = myRightMargin + outsideMarginChange;

                    var myInsideMargin = pageRef.marginPreferences.left;

                   pageRef.marginPreferences.right = myOutsideMargin;

            //to change text frame; assumes text frame fits to margins

                  var pageWid = pageRef.bounds[3] - pageRef.bounds[1];

                   var pageHgt = pageRef.bounds[2] - pageRef.bounds[0];

                   var textFrameRef = pageRef.textFrames.item(0);

                   var topMargin = pageRef.marginPreferences.top;

                   var botMargin = pageRef.marginPreferences.bottom;

                   var gWidth;

                   var gHgt = (pageHgt - botMargin);

                   if (pageRef.side == PageSideOptions.LEFT_HAND) {

                   gWidth = (pageWid - myInsideMargin);

                  textFrameRef.geometricBounds = [topMargin, myOutsideMargin, gHgt, gWidth];

                  var test = [topMargin, myOutsideMargin, gHgt, gWidth];

                   } else {

                    gWidth = (pageWid - myOutsideMargin);

                   textFrameRef.geometricBounds = [topMargin, myInsideMargin, gHgt, gWidth];

                   }

            }

            • 3. Re: Script for Increasing or decreasing page width
              Math Kay Level 1

              Hi Hopkins,

              Thank you so much for this great response. I need changes in all master pages but not directly in the document pages.  Also when we do modifications, new pages should be inserted for flowing text if text width was decreased and extra pages should be deleted if text width increased  automatically. Please look into this.

               

              Thanks

              Math Kay