Your prescription for increased productivity and profitability
When a document is exported to EPub, by default Adobe InDesign exports items in order of front page to back, left to right, top to bottom. If this is not what you want, you have several options:
In working with the Articles Panel:
When selecting items for inclusion in the Articles Panel:
When you have story segments scattered throughout a sizable document, selection is out of the question. If related stories have an attribute that is unique, you can filter the stories by attribute and combine the segments into a single story thread.
First you need to get a list of the stories (or story containers) by attribute. (See our blog post for July 22, 2013).
Once you have the list, you can parse through the list and thread the stories together using a script. This story can then be added to the Articles Panel
Some story segments may have more than one text frame within its link. You will need to filter through the stories and get a list of just the first text frames for each text thread. This can be done using one of the following:
AppleScript
tell application "Adobe InDesign CC" tell document 1 set firstFrames to {} set textFrameList to text frames repeat with i from 1 to length of textFrameList if class of parent of item i of textFrameList is not master spread then if previous text frame of item i of textFrameList is nothing then set end of firstFrames to item i of textFrameList end if end if end repeat end tell end tell
ExtendScript
var docRef = app.documents.item(0); var firstFrames = []; var textFrameArr = docRef.textFrames; var thisItem; for (var i = 0; i < textFrameArr.length; i++) { thisItem = textFrameArr[i]; if (thisItem.parent.constructor.name != "MasterSpread") { if (thisItem.previousTextFrame == null) { firstFrames.push(thisItem); } } }
AppleScript
set styleName to "Note" --get paragraph style name from user tell application "Adobe InDesign CC" tell document 1 set styleRef to paragraph style styleName set storyList to stories set firstFrames to {} --get filtered list repeat with i from 1 to length of storyList set thisStory to item i of storyList tell thisStory to set thisContainer to item 1 of text containers if class of parent of thisContainer is not master spread then if (previous text frame of thisContainer is nothing and applied paragraph style of paragraph 1 of thisStory = styleRef) then set end of firstFrames to thisContainer end if end if end repeat end tell end tell
ExtendScript
var styleName = "Note"; //get name of style from user main(); function main(){ var docRef = app.documents.item(0); var styleRef = docRef.paragraphStyles.itemByName(styleName); var firstFrames = []; var storyArr = docRef.stories; var thisStory, thisContainer; for (var i = 0; i < storyArr.length; i++) { thisStory = storyArr[i]; thisContainer = thisStory.textContainers[0]; if (thisContainer.parent.constructor.name != "MasterSpread") { if (thisContainer.previousTextFrame == null && thisStory.paragraphs.item(0).appliedParagraphStyle == styleRef) { firstFrames.push(thisContainer); } } } }
Once you have a list of filtered first frames, you can parse through the list to combine the stories into a single thread:
AppleScript
set articleName to "MyArticle" --get article name from user tell application "Adobe InDesign CC" set docRef to document 1 tell docRef set masterStory to parent story of item 1 of firstFrames set lastFrame to missing value repeat with i from 1 to length of firstFrames set thisFrame to item i of firstFrames set testFrame to end text frame of thisFrame --if lastFrame is not missing value then --link the current frame to the lastFrame if lastFrame is not missing value then set previous text frame of thisFrame to lastFrame end if --set up the lastFrame variable for the next iteration if testFrame is not thisFrame then set lastFrame to end text frame of thisFrame else set lastFrame to thisFrame end if --make sure stories do not run together my testEndCharacter(docRef, masterStory) end repeat tell masterStory set masterFrame to item 1 of text containers end tell set articleRef to make article with properties {name:articleName} tell articleRef to make article member with properties {item ref:masterFrame} end tell end tell --HANDLER on testEndCharacter(docRef, storyRef) tell application "Adobe InDesign CC" tell docRef if contents of insertion point -1 of storyRef is not return then set contents of insertion point -1 of storyRef to return end if end tell end tell end testEndCharacter
ExtendScript
var articleName = "MyArticle"; //get name of article from user function combineStories(docRef, firstFrames) { masterStory = firstFrames[0].parentStory; var lastFrame, thisFrame, testFrame; for (var i = 0; i < firstFrames.length; i++) { thisFrame = firstFrames[i]; testFrame = thisFrame.endTextFrame; if (lastFrame != undefined) { thisFrame.previousTextFrame = lastFrame; } //set up the lastFrame variable for the next iteration if (testFrame.id != thisFrame.id) { lastFrame = thisFrame.endTextFrame; } else { lastFrame = thisFrame; } testEndCharacter (masterStory); } //Add story to article var masterFrame = masterStory.textContainers[0]; var articleRef = articles.add({name:articleName}); articleRef.articleMembers.add({itemRef:masterFrame}); function testEndCharacter (storyRef){ if (storyRef.insertionPoints.lastItem().contents != "\r"){ storyRef.insertionPoints.lastItem().contents = "\r"; } } }
Add finishing touches to the code above to make your own script. We will be adding a more complete script to an EPub script collection to be posted later.