Friday, December 08, 2006

 

Story on Live Pages

I'm working with a document that has a lot of busy master spreads. But what I needed was to identify a particular story on the live pages. The frames are labeled, but so are the original frames on the master pages. So, it occurred to me to wonder if I could easily get a list of all the frames on the live pages of a document, ignoring the ones on the master pages.

Turns out that a double-dose of everyItem() gets the job done:
myFrames = doc.pages.everyItem().textFrames.everyItem().getElements();
This produces an array of all the text frames free-standing on the live pages of a document. So, I can examine that list to find the story of interest without having to be concerned about the master frames that have the same label.

Speaking of labeling, I used this in a function that records the identity of the story of interest in a document label, so that the story only has to be found once:
  function getMainStory(doc) {
    var label = doc.extractLabel("Main Story")
    if (label != "") {
      return doc.stories.itemByID(Number(label));
    } else {
      var myFrames = doc.pages.everyItem().textFrames.everyItem().getElements();
      for (var j = myFrames.length - 1; j >= 0; j--) {
        if (myFrames[j].extractLabel("Frame Type") == "Main Story Frame") {
          var myStoryID = myFrames[j].parentStory.id;
          doc.insertLabel("Main Story", String(myStoryID));
          return doc.stories.itemByID(myStoryID)
        }
      }
    }
  } // end getMainStory
I'm not fully convinced that this is the most efficient way of achieving this goal, but it works and after the first time, it is very quick.

Comments:
I recently had a similar issue. I was working on a script to create a 2007 calendar from Excel. The containers for days of the week & weekly header are on a master spread and have script labels. I found that allPageItems didn't return any masterpage objects. I stepped through the appliedMaster.allPageItems collection to processes the text frames I wanted. Here is the VB code for the loop.

Set oSpread = oDoc.Spreads.Add(idAtEnd, "A")
For Each oItem In oSpread.AppliedMaster.AllPageItems
Select Case oItem.Label
Case "Header_Even"
' Do something with the Even Header textframe
Case "Header_Odd"
' Do something with the Odd Header textframe
Case Else
End Select
Next oItem
 
Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?