2009-07-24

Get MediaSpan Jazbox Graphic Captions

Another piece of the puzzle

Earlier I posted a function to look at an Adobe InCopy story from a MediaSpan Jazbox site that had multiple Text Elements and create a special object sometimes called an associative array. The graphic captions will be part of that special object. But their 'storyTitle' is only partly predictable because the 'storyTitle's always include the name of the graphic. So while we know they start with 'Graphic' and are followed by a number and a colon, the text after the colon is unknown. But with a Regular Expression we can find those stories whose 'storyTitle' property starts properly.

The function below will give you a reference to all the stories (InCopy's definition of a story, not yours and mine) in the passed document reference which are graphic captions. From there you can use a script to format them or do other things with them.




//
function getJazboxGraphicCaptionStories ( JazboxStoryElements ) {
//-------------------------------------------------------------------------
//-- G E T J A Z B O X G R A P H I C C A P T I O N S
//-------------------------------------------------------------------------
//-- Generic. Almost. Requires an external function.
//-------------------------------------------------------------------------
//-- Purpose: To return an array with a reference to each Jazbox caption.
//-------------------------------------------------------------------------
//-- Arguments: 1
//-- JazboxStoryElements: A custom object with properties continging
//-- each element of a story. The properties are named with the
//-- 'StoryTitle' (the text in the gray bar above each element
//-- in Adobe InCopy). For Jazbox captions, these 'storyTitle's
//-- start with "Graphic", a number, and a colon followed by
//-- a space and the image "Name". The routine to create the
//-- Jazbox elements might have these storyTitles generated
//-- with or without spaces and odd characters in their names
//-- so be careful with that.
//-------------------------------------------------------------------------
//-- Returns: An array of stories that point to the Jazbox captions.
//-------------------------------------------------------------------------
//-- Calls: Nothing.
//-------------------------------------------------------------------------
//-- Sample Use: Perhaps you wanted to get a reference to every caption
//-- 'story' in the active Adobe InCopy document. This might be
//-- useful if you had a function to format all the captions, but
//-- needed a method to find and access them. This function can
//-- return an array which can be looped through to point another
//-- funciton to the each caption to format.
//--
//~ var allCaptions = getJazboxGraphicCaptionStories ( getJazboxStoryElements ( app.documents[0] ) ) ;
//~ for ( var captionIndex = 0 ; captionIndex < allCaptions.length ; captionIndex++ ) {
//~ //-- Do what you want with the catptions
//~ formatCaption ( allCaptions[captionIndex] )
//~ }
//~ function formatCaption ( aCaption ) {
//~ try {
//~ aCaption.appliedParagraphStyle = '03_CAPTION_caption'
//~ }
//~ catch (err) { /* nothing to do */ }
//~ }
//--
//-------------------------------------------------------------------------
//-- Written: 2009.07.03 by Jon S. Winters of electronic publishing support
//-- eps@electronicpublishingsupport.com
//-------------------------------------------------------------------------

//-- Add a way for the site to limit how many captions are looked at.
var maximumNumberOfRelatedItemsAtSite = 50 ;

//-- Construct a string of all the element names to be used as a test
//-- for determining if a particular caption exists.
var storyProperties = JazboxStoryElements.reflect.properties ; // This generates an array
var storyPropertyNamesString = storyProperties.join('\t') ; // This makes the string
var numProperties = storyProperties.length ; // note there will always be some, but there may not be real captions.

//-- Construct the return array
var captions = new Array () ;

//-- Loop through the available captions
for ( var captionIndex = 0 ; captionIndex < maximumNumberOfRelatedItemsAtSite ; captionIndex++ ) {
//-- Construct a Regular Expression pattern for this Jazbox caption number
//-- IMPORTANT: if check the case of the text from the routine to get the elements.
var captionPattern = new RegExp ( 'graphic' + captionIndex + ':' , 'i' ) ;
//-- See if that caption exists before trying to find a particular reference
if ( captionPattern.test ( storyPropertyNamesString ) ) {
//-- The particualr caption exists, now find a reference to it.
for ( propertyIndex = 0 ; propertyIndex < numProperties ; propertyIndex++ ) {
if ( captionPattern.test ( storyProperties[propertyIndex] ) ) {
var fullPropertyName = storyProperties[propertyIndex].name ;
captions.push( JazboxStoryElements[fullPropertyName] ) ;
}
}
}
}
//
return captions ;
}
//

No comments:

Post a Comment