Skip navigation
Josh000000 30 posts
Nov 1, 2011
Currently Being Moderated

Auto master page application

Apr 12, 2012 9:32 AM

Tags: #event #master #event_listener #master_page #idle #idle_task

I wrote this script to see if I could hook master pages to a paragraph style and I have a couple of questions.

 

1. Currently I'm using the "onIdle" event type is there a better event type that could be used that would still run without interrupting the user?

 

I was thinking the "afterAttributeChanged" event type might work better. When is this one called? Is it called for every attribute change in the layout window?

 

 

2. I'm also searching for the pages that I want to change via grep and grabbing the page with paragraphs[i].parentTextFrames[0].parentPage;

 

Is this the most efficient way to do this?

 

 

Here's what I have so far:

 

#targetengine "session"
 
var doc = app.activeDocument;
 
var chapterStyleGroup = doc.paragraphStyleGroups.itemByName("Chapter");
var chapterTitle = chapterStyleGroup.paragraphStyles.itemByName("ChapterTitle");
 
var aMaster = doc.masterSpreads.itemByName("A-Master");
var cMaster = doc.masterSpreads.itemByName("C-Chapter Open");
 
var chapterPages = [];
 
app.findGrepPreferences = NothingEnum.nothing;
app.findGrepPreferences.appliedParagraphStyle = chapterTitle;
var paras = app.findGrep();
for (var i=0, l=paras.length; i<l; i++) {
          var parentPage = paras[i].parentTextFrames[0].parentPage;
          chapterPages.push(parentPage);
          parentPage.appliedMaster = cMaster;
};
 
var listenerTask = app.idleTasks.add({sleep: 5000});
listenerTask.addEventListener("onIdle", checkPages);
 
function checkPages() {
          var savedPrefs = app.findGrepPreferences.properties;
          app.findGrepPreferences = NothingEnum.nothing;
          app.findGrepPreferences.appliedParagraphStyle = chapterTitle;
          var paras = app.findGrep();
 
          for (var i=0, l=paras.length; i<l; i++) {
                    var parentPage = paras[i].parentTextFrames[0].parentPage;
                    if (chapterPages[i] !== parentPage) {
                              chapterPages[i].appliedMaster = aMaster;
                              parentPage.appliedMaster = cMaster;
                              chapterPages.splice(i,1,parentPage);
                    }
          };
          app.findGrepPreferences.properties = savedPrefs;
}


 

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points