I'm at a site this week that currently has 947 Paragraph Styles. I needed a list of them. Here is an ExtendScript to list them into a selected text frame in an Adobe InDesign page. This was a quick hack, so no verbose comments.
Note the two different ways of referencing the document. The first method uses a function posted here. Delete that line if you don't want to use it (no real need in this case).
Oh, and here with the 900+ Paragraph Styles, we had to add 7 more broadsheet pages to show the styles.
try {
    //see if there is a parentStory. If so, then fill it with the names of the styles
    //-- The next line errors if there isn't a proper selection
    var storyRef = app.selection[0].parentStory.textContainers[0].parentStory ;
   
    //-- Get a valid reference to the document holding the story
    var docRef = returnDocumentReference ( storyRef ) ;
    //OR use
    var docRef = app.documents[0];
   
    //-- Call the function to add the styles.
    listParagraphStyles ( storyRef , docRef )
}
catch (err) {
    //-- The next line quits the script.
    exit() ;
}
//
function listParagraphStyles ( storyRef , docRef ) {
    //-- Clear the contents of the the frame
    storyRef.contents = '\r' ;
    //-- Get an array of all the Paragraph Styles
    var allPS = docRef.allParagraphStyles ;
    var numPS = allPS.length ;
   
    //-- Loop through the styles adding the name of the style and applying that style to the story
    for ( var pIndex = 0 ; pIndex < numPS ; pIndex++ ) {
        storyRef.paragraphs[pIndex].contents = allPS[pIndex].name + '\r ' ; //note the space after the return
        //-- Remove the next line if you don't want to see the style name formatted with that
Paragraph Style.
        storyRef.paragraphs[pIndex].appliedParagraphStyle = allPS[pIndex] ;
    }
}   
//
2009-07-14
Listing Paragraph Styles
Labels:
Adobe,
Every,
ExtendScript,
Function,
InCopy,
InDesign,
JavaScript,
List,
Paragraph,
Style
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment