Article View: adobe.scripting.indesign
Article #21026Re: Search and replace elements with particular character style
From: Alan Stearns
Date: Sat, 18 May 2002 14:32
Date: Sat, 18 May 2002 14:32
15 lines
1929 bytes
1929 bytes
Given theApp for your application, and theDoc for your doc, try something like this:
' Set up find/change preferences to find a particular character style Set FindStyle = theDoc.CharStyles.Item("Character Style 1") theApp.FIndPreferences = idNothing ' clear out existing data theApp.FindPreferences.CharacterStyle = FindStyle theApp.ChangePreferences = idNothing ' clear out existing data theApp.ChangePreferences.CharacterStyle = FindStyle
' get a collection of text objects that have that style applied Set FoundText = theDoc.Search ("",,,"")
' iterate over the collection backwards (to avoid invalidating the text references) For X = FoundText.Count to 1 Step -1
' do something to FoundText.Item(X), like: FoundText.Item(X).InsertionPoints.Item(1).TextConents = "*"
Next X
The Search function also works on the application (getting text references in all open documents) for something like this if you have character styles in different documents with the same name.
I've set the character style in ChangePreferences as well to avoid having the Search function change any of the text (postponing all the changes to the subsequent loop).
Technical Details
Message-ID:
<ef89ad8.2@WebX.aaQKaf7vad4>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!supernews.com!newspump.sol.net!news.maxwell.syr.edu!fr.clara.net!heighliner.fr.clara.net!newsfeed01.sul.t-online.de!t-online.de!WebXReferences:
<ef89ad8.-1@WebX.aaQKaf7vad4>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f939a,2b4ea2d024f5065d X-Google-Attributes: gidf939a,public X-Google-ArrivalTime: 2002-05-18 08:07:26 PST From: "Alan Stearns" <astearns@adobe.com> Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!supernews.com!newspump.sol.net!news.maxwell.syr.edu!fr.clara.net!heighliner.fr.clara.net!newsfeed01.sul.t-online.de!t-online.de!WebX Newsgroups: adobe.scripting.indesign Subject: Re: Search and replace elements with particular character style Message-ID: <ef89ad8.2@WebX.aaQKaf7vad4> Date: Sat, 18 May 2002 07:32:39 -0700 References: <ef89ad8.-1@WebX.aaQKaf7vad4> Lines: 31 MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8bit