Applying a master based on paragraph style
Learn / Forums / General InDesign Topics / Applying a master based on paragraph style
Tagged: master pages, paragraph style
- This topic has 9 replies, 1 voice, and was last updated 2 years, 3 months ago by Civi Bernath.
-
AuthorPosts
-
-
November 13, 2016 at 12:47 pm #89700Rivkah LewisMember
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!
-
November 14, 2016 at 7:03 am #89732David BlatnerKeymaster
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. -
November 14, 2016 at 2:07 pm #89745Rivkah LewisMember
Thanks, David.
-
November 7, 2017 at 6:16 pm #99448Khalid HussainMember
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"); } }
-
November 7, 2017 at 11:47 pm #99450Rivkah LewisMember
Interesting! Thanks for sharing, Khalid.
I will try that next time it comes up in a job. -
February 1, 2018 at 6:38 am #101341Rivkah LewisMember
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?
-
February 1, 2018 at 8:44 am #101344David BlatnerKeymaster
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 -
February 1, 2018 at 12:40 pm #101360Rivkah LewisMember
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”);
}
} -
February 5, 2018 at 11:59 pm #101477Rivkah LewisMember
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. -
January 2, 2022 at 10:19 am #14354092Civi BernathParticipant
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.
-
-
AuthorPosts
- You must be logged in to reply to this topic.