6 Replies Latest reply on May 13, 2016 1:58 PM by InfernoDandA

    how to automatically apply A & B master pages consecutively...

    InfernoDandA Level 1

      More specifically, I want to automatically apply A & B master pages consecutively to a document across all of it's pages.

       

      I found this bit of code in the sample scripts and figured out how to apply B master to a single page (page 3 in this case)

       

      var myDocument = app.activeDocument;
      var myPage = myDocument.pages.item(2);


       

      myPage.appliedMaster = myDocument.masterSpreads.item("B-Master");

       

       

      but now I'm totally stumped as to how to proceed.


      I figure I need a function to find out how many pages are in my document, and then apply the B master to each next page until it reaches the end.

      so for example my document is 6 pages long, when I create it just has A master applied to all pages, so A, A, A, A, A, A

      but I want it to go A, B, A, B, A, B.
      easy enough task to do manually I know for 6 pages but would be very handy on much longer documents.....


      any help would be appreciated, I'm new to all this and just trying to figure out how to do a few useful things

      Thanks!

        • 1. Re: how to automatically apply A & B master pages consecutively...
          tpk1982 Level 4

          Hi...

           

          I created this to apply alternative master pages for document using left and right option.. try this

           

           

           

          var d = app.documents[0];
          var myDialog = app.dialogs.add ({name:"APPLY MASTERPAGE",canCancel:true});
          var allMasters = new Array;
          for (i=0; i<app.activeDocument.masterSpreads.length; i++)
            allMasters.push(app.activeDocument.masterSpreads[i].name);
          
          
          with (myDialog)
          {
            with (dialogColumns.add())
            {
          
            with (dialogRows.add())
            {
            staticTexts.add ({staticLabel:"LEFT   "});
            myleft = dropdowns.add ({stringList:allMasters, selectedIndex:0});
            }
            with (dialogRows.add())
            {
            staticTexts.add ({staticLabel:"RIGHT"});
            myright = dropdowns.add ({stringList:allMasters, selectedIndex:0});
            }
            }
          }
          if (myDialog.show() == true)
          {
          for(var p=0;p<d.pages.length;p++){  
          
            //Looking for RIGHT hand pages:  
              if(d.pages[p].side == PageSideOptions.RIGHT_HAND){  
                  d.pages[p].appliedMaster = d.masterSpreads.item(allMasters[myright.selectedIndex])
                  };  
            
              if(d.pages[p].side == PageSideOptions.LEFT_HAND){  
                  d.pages[p].appliedMaster = d.masterSpreads.item(allMasters[myleft.selectedIndex])  
                  }  
               }
          }
          
          • 2. Re: how to automatically apply A & B master pages consecutively...
            tpk1982 Level 4

            the below coding is striaght forward

             

            var d=app.documents[0];  
            var masterSpreadsD = d.masterSpreads;  
            var pagesD = d.pages;  
            var totalNumber = 2;  
            var master1Name = "A-Master";  
            var master2Name = "B-Master";  
            for(var n=0;n<pagesD.length;n=n+totalNumber){  
                pagesD[n].appliedMaster = masterSpreadsD.itemByName(master1Name);  
                };  
            for(var n=1;n<pagesD.length;n=n+totalNumber){  
                pagesD[n].appliedMaster = masterSpreadsD.itemByName(master2Name);  
                };  
            
            • 3. Re: how to automatically apply A & B master pages consecutively...
              karthiks94217840 Level 2

              Hi TPK,

               

              Your both is coding working super.

               

              Thanks

              • 4. Re: how to automatically apply A & B master pages consecutively...
                InfernoDandA Level 1

                Great, this is exactly what I wanted!
                It's much appreciated Tpk1982

                 

                I usually work with facing pages turned off but the first script is perfect for times when that's turned on too.

                Will be good for me to have a go at reverse engineering that one to try and understand what the hell's going on

                 

                Thanks again!

                • 5. Re: how to automatically apply A & B master pages consecutively...
                  tpk1982 Level 4

                  You may add this line to check whether facing page status

                   

                  if(d.documentPreferences.facingPages == false){

                      alert("This script will only work on documents with facing pages!");

                      null;

                      };

                   

                  or you can turn off the facing page when strating

                  if(d.documentPreferences.facingPages == true){ 

                      d.documentPreferences.facingPages == false 

                      }; 

                  • 6. Re: how to automatically apply A & B master pages consecutively...
                    InfernoDandA Level 1

                    ah, this is even better tpk1982.
                    I combined the two scripts in one (easier to keep track of things) and now just check for facing pages and do either one.

                     

                    Thanks