3 Replies Latest reply on Feb 28, 2016 8:40 AM by cudspan

    Applying custom MasterPage using Extendscript

    skinjp Level 1

      Is it even possible?

      The closest I've gotten to it is about 2 steps shy of actually applying the custom masterpage.



      This gets the dialog box open but how do you choose the custom masterpage by name and apply it without opening a dialog box?

      And on the flip side, if a custom masterpage is already set, how do you change it back to the default, "Right"?



        • 1. Re: Applying custom MasterPage using Extendscript
          JoH Level 2

          To my understanding, the Fcodes command is a way to simulate user input, therefore you get the dialog.


          You can set the master page using this code:


          // Optional: Get the current page of the active document
          var doc, page;
          doc = app.ActiveDoc;
          page = doc.CurrentPage;
          // Apply a master page called "Separator"
          page.PageBackground = Constants.FV_BGD_OTHER;
          page.MasterPage = "Separator";

          To revert to the default master page, use


          page.PageBackground = Constants.FV_BGD_DEFAULT;
          • 2. Re: Applying custom MasterPage using Extendscript
            skinjp Level 1

            Excellent. Thank you!

            • 3. Re: Applying custom MasterPage using Extendscript
              cudspan Level 1

              Actually, your instructions only set the background.  If the master page has a different layout (like the FIRST page might have more white space above the text frame), then you actually have to apply the master page formatting, like so...


              var doc = app.ActiveDoc;

              var first = doc.GetNamedMasterPage('First');

              var right = doc.GetNamedMasterPage('Right');

              var left = doc.GetNamedMasterPage('Left');




              // If you have a page that needs "First", then you can say:



              //To reset all pages to defaults, you would need to say:


              page = doc.FirstBodyPageInDoc;

              while(page.ObjectValid()) {

                   if(page.PageIsRecto) {


                   } else {