Applying a master based on paragraph style

Learn / Forums / General InDesign Topics / Applying a master based on paragraph style

Viewing 9 reply threads
  • Author
    Posts
    • #89700
      Rivkah Lewis
      Member

      Is there a way to apply a master to a page based on a paragraph style found on that page?
      I have a document set up for a book.
      A graphic is being added behind the chapter number.
      But I didn’t initially make a separate master for the chapter header pages because a)the pages shift once proofread and b) it wasn’t necessary when there was no image there – it was all differentiated through styles.

      So I’m looking for a faster way that going through the entire almost 400-pg book to find the beginning of each chapter and quick apply a master page.

      Thanks!

    • #89732
      David Blatner
      Keymaster

      InDesign itself doesn’t do that, but there are third-party tools that can help, including:
      https://www.id-extras.com/products/mastermatic
      and
      https://in-tools.com/products/autoflow-pro/
      Both of these can save many hours of time, making the small cost worthwhile.

    • #89745
      Rivkah Lewis
      Member

      Thanks, David.

    • #99448

      I know this is late but it’ll be a good reference for future visitors.

      I believe your question has been answered here: https://forums.adobe.com/thread/1027292

      Just in case the website doesn’t exist in the future, here’s the code:

      var myDocument = app.activeDocument;
      var myParas = myDocument.stories.everyItem().paragraphs.everyItem().getElements();
      var myPage = myDocument.pages;
      for(i=0; i<myParas.length; i++)
      {
          if(myParas[i].appliedParagraphStyle.name == "CT")  
          {
              //Works only in CS5 and later
              myParas[i].parentTextFrames[0].parentPage.appliedMaster = myDocument.masterSpreads.item("B-Master");
              //for CS4 use this
              //myParas[i].parentTextFrames[0].parent.appliedMaster = myDocument.masterSpreads.item("B-Master");
          }
      }
      
    • #99450
      Rivkah Lewis
      Member

      Interesting! Thanks for sharing, Khalid.
      I will try that next time it comes up in a job.

    • #101341
      Rivkah Lewis
      Member

      I was super-excited to try this out… but I must be doing something wrong.
      I’d love to tag someone like Jongware – is that possible here??

      I really know nothing about scripting, but after I tried running it, I thought perhaps I was supposed to replace the text in the script with the name of my paragraph style. It still doesn’t work.

      Can anyone help?

    • #101344
      David Blatner
      Keymaster

      Hi Rivkah: I just tried the script above and it works great. It needs some customization for your situation, of course. In this case, it is looking for a paragraph style called “CT” and when it finds it, it applies “B-Master” to that page. You can change “CT” and “B-Master” in the script to your specific paragraph style and master page name.

      Here is an article that shows how to save the script and install it:
      https://creativepro.com/how-to-install-a-script-in-indesign-that-you-found-in-a-forum-or-blog-post.php

    • #101360
      Rivkah Lewis
      Member

      Thanks for taking the time to try it out and reply.
      I had found that article and followed the instructions.

      I was changing the style name incorrectly ::blushing::

      But now I’m getting a java script error 21 that the problem is with the following line
      myParas[i].parentTextFrames[0].parentPage.appliedMaster = myDocument.masterSpreads.item(“B-Master”);

      I tried
      1. changing “B-Master”to my master name. I assumed I was supposed to keep the letter heading. Mine also is B so I wrote it as “B-chapterpage”
      2. When that didn’t work, I changed the name of my master back to B-Master and reset that part of the script to the original, changing only the style name.

      And I’m getting that error. What am I doing wrong?

      This is what my personalized script now looks like:

      var myDocument = app.activeDocument;
      var myParas = myDocument.stories.everyItem().paragraphs.everyItem().getElements();
      var myPage = myDocument.pages;
      for(i=0; i<myParas.length; i++)
      {
      if(myParas[i].appliedParagraphStyle.name == “chapternumber”)
      {
      //Works only in CS5 and later
      myParas[i].parentTextFrames[0].parentPage.appliedMaster = myDocument.masterSpreads.item(“B-Master”);
      //for CS4 use this
      //myParas[i].parentTextFrames[0].parent.appliedMaster = myDocument.masterSpreads.item(“B-Master”);
      }
      }

    • #101477
      Rivkah Lewis
      Member

      I am really embarrassed, but for the record I have to say that it worked beautifully.
      I did in fact get an error message and therefor did not bother checking that it had in fact applied the master to those pages!
      So I’m still not sure what the error message was about, but I LOVE this script.
      Thanks for posting it, Khalid and thanks for your comments, David.

    • #14354092
      Civi Bernath
      Participant

      This script is really cool. Only problem is, if you edit your text after applying the script, thereby moving the new chapter to the next spread, you need to start all over again. If you have just one master spread aside from the chapter spread, no problem. Just reapply all lto the base master and then run the script again. For me, I’ll probably but the Mastermatic add-on that David indicated at the beginning of this thread. It updates the application of master pages as you go.

Viewing 9 reply threads
  • You must be logged in to reply to this topic.
>