Adobe 0046100128056 Scripting Guide - Page 99
Deleting a style, Importing paragraph and character styles
UPC - 718659087562
View all Adobe 0046100128056 manuals
Add to My Manuals
Save this manual to your list of manuals |
Page 99 highlights
CHAPTER 6: Text and Type Formatting Text 99 Why use the applyParagraphStyle method instead of setting the appliedParagraphStyle property of the text object? The applyParagraphStyle method gives the ability to override existing formatting; setting the property to a style retains local formatting. Why check for the existence of a style when creating a new document? It always is possible that the style exists as an application default style. If it does, trying to create a new style with the same name results in an error. Nested styles apply character-style formatting to a paragraph according to a pattern. The following script fragment shows how to create a paragraph style containing nested styles (for the complete script, see NestedStyles): var myDocument = app.documents.item(0); var myPage = myDocument.pages.item(0); var myTextFrame = myPage.textFrames.item(0); var myParagraphStyle = myDocument.paragraphStyles.item("myParagraphStyle"); var myNestedStyle = myParagraphStyle.nestedStyles.add({appliedCharacterStyle:myCharacterStyle, delimiter:".", inclusive:true, repetition:1}); var myStartCharacter = myTextFrame.parentStory.characters.item(0); var myEndCharacter = myTextFrame.parentStory.characters.item(-1); //Use the itemByRange method to apply the paragraph to all of the text in the story. //(Note that the story object does not have the applyParagraphStyle method.) myTextFrame.parentStory.texts.itemByRange(myStartCharacter, myEndCharacter).applyParagraphStyle(myParagraphStyle, true); Deleting a style When you delete a style using the user interface, you can choose the way you want to format any text tagged with that style. InDesign scripting works the same way, as shown in the following script fragment (from the RemoveStyle tutorial script): var myDocument = app.activeDocument; var myParagraphStyleA = myDocument.paragraphStyles.item("myParagraphStyleA"); //Remove the paragraph style myParagraphStyleA and replace with myParagraphStyleB. myParagraphStyleA.remove(myDocument.paragraphStyles.item("myParagraphStyleB")); Importing paragraph and character styles You can import character and paragraph styles from other InDesign documents, as shown in the following script fragment (from the ImportTextStyles tutorial script): //Create a new document. myDocument = app.documents.add(); //Import the styles from the saved document. //importStyles parameters: // Format as ImportFormat enumeration. Options for text styles are: // ImportFormat.paragraphStylesFormat // ImportFormat.characterStylesFormat // ImportFormat.textStylesFormat // From as File // GlobalStrategy as GlobalClashResolutionStrategy enumeration. Options are: // GlobalClashResolutionStrategy.doNotLoadTheStyle // GlobalClashResolutionStrategy.loadAllWithOverwrite // GlobalClashResolutionStrategy.loadAllWithRename myDocument.importStyles(ImportFormat.textStylesFormat, File("/c/styles.indd"), GlobalClashResolutionStrategy.loadAllWithOverwrite);