Article View: adobe.scripting.indesign
Article #18058Re: AS changing text attributes
From: Olav Kvern
Date: Fri, 25 Apr 2003 21:43
Date: Fri, 25 Apr 2003 21:43
36 lines
2512 bytes
2512 bytes
John-- You know, there are probably as many ways to accomplish this as there are scripters. Iolaire's approach--processing the text outside InDesign--is a good one (though I think using InDesing tagged text might be a bit better than RTF). But let's assume that you want to do this inside InDesign. One reasonable approach would be to use the search method to populate one list with each place you found "[BOLD]" and then populate another with the corresponding list of "[UNBOLD]" items. Since the item at a given index in each list will match a corresponding item in the other list, and since each is a reference to an InDesign text object (and therefore carries with it information about its location in the story, you can do something like this (this assumes you have a character style named "bold" defined): tell application "InDesign 2.0.2" set find preferences to nothing set change preferences to nothing tell active document set myCharacterStyle to character style "bold" set myStartItems to search for "[BOLD]" set myEndItems to search for "[UNBOLD]" if (count myStartItems) is not equal to (count myEndItems) then display dialog "Oops. The text must include mismatched formatting. Good luck finding the offending tags!" else repeat with myCounter from 1 to (count myStartItems) set myStartItem to item myCounter of myStartItems set myStory to object reference of parent story of myStartItem set myEndItem to item myCounter of myEndItems set myStartIndex to (index of character -1 of myStartItem) + 1 set myEndIndex to (index of character 1 of myEndItem) - 1 set applied character style of characters myStartIndex through myEndIndex of myStory to myCharacterStyle end repeat end if end tell end tell Thanks, Ole
Technical Details
Message-ID:
<1de8dffa.1@WebX.la2eafNXanI>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-01!sn-xit-09!supernews.com!diablo.theplanet.net!news.maxwell.syr.edu!eusc.inter.net!newsfeed01.sul.t-online.de!t-online.de!WebXReferences:
<1de8dffa.-1@WebX.la2eafNXanI>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f939a,3f638a313e6d5906 X-Google-Attributes: gidf939a,public X-Google-ArrivalTime: 2003-04-25 15:08:05 PST From: "Olav Kvern" <okvern@adobe.com> Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-01!sn-xit-09!supernews.com!diablo.theplanet.net!news.maxwell.syr.edu!eusc.inter.net!newsfeed01.sul.t-online.de!t-online.de!WebX Newsgroups: adobe.scripting.indesign Subject: Re: AS changing text attributes Message-ID: <1de8dffa.1@WebX.la2eafNXanI> Date: Fri, 25 Apr 2003 14:43:57 -0700 References: <1de8dffa.-1@WebX.la2eafNXanI> Lines: 44 MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8bit