2009-07-22

Add Note and Text to End Of Story

Part of a Story Aggregator

For a MediaSpan Jazbox site I was working at there was a need to access specific Text Elements and combine them into a specific order (look for a future post for more details). Note: If you are a Jazbox site, MediaSpan's CSS can do this same function without any user interaction. This was for a very special purpose that the site decided to script a different solution.

Back to the script... Part of adding different blobs of text together into a new Adobe InCopy story involved marking them with their original Text Element name. Notes seemed like a good choice. So this function was developed to take a reference to a story and add a note and some more text to the end of the story. It works well. While designed for Adobe InCopy this would also work for Adobe InDesign as well.


//
function addNoteAndTextToEndOfStory ( storyRef , noteString , storyString ) {
//-------------------------------------------------------------------------
//-- A D D N O T E A N D T E X T T O E N D O F S T O R Y
//-------------------------------------------------------------------------
//-- Generic: Yes for Adobe InCopy and Adobe InDesign CS3 and perhaps newer
//-------------------------------------------------------------------------
//-- Purpose: To add a note and then some text following the note at the
//-- current end of the passed Adobe InDesign or Adobe InCopy story.
//-- The original reason to do this was for a client that wanted to
//-- aggregate some paragraphs of text, but record where the text
//-- came from. So, by passing this function a reference to a story
//-- it will add a note and then the text to the end of the story.
//--
//-- Note: this function is currently set to add a blank
//-- paragraph at the end of the story each time this is to help
//-- place each subsequent addition at the beginning of a paragraph.
//-------------------------------------------------------------------------
//-- Calls: Nothing.
//-- Returns: Nothing, but modifies the story for the passed reference.
//-------------------------------------------------------------------------
//-- Sample Use:
//~ var storyRef = app.documents[0].stories[0] ;
//~ var noteContents = 'This is a note Added by A Script' ;
//~ var storyContents = 'The FirstParagraph\rThe Second\rFinal Paragraph'
//~ addNoteAndTextToEndOfStory ( storyRef , noteContents , storyContents )
//-------------------------------------------------------------------------
//-- Written: 2009.07.03 by Jon S. Winters of electronic publishing support
//-- eps@electronicpublishingsupport.com
//-------------------------------------------------------------------------
//-- To add a note to a story, we need to first add the note using the
//-- .add method. That returns a reference to the added note. The
//-- resultant note doesn't have contents, but its 'texts' does.
var noteRef = storyRef.insertionPoints[-1].notes.add() ;
noteRef.texts[0].contents = noteString ;

//-- Now insert the contents at the end of the story and add a return.
storyRef.insertionPoints[-1].contents = storyString + '\r' ;
}
//

No comments:

Post a Comment