Article View: adobe.scripting.indesign
Article #20594VB Getting an arbitrary range of text
From: Olav Kvern
Date: Thu, 13 Jun 2002 18:43
Date: Thu, 13 Jun 2002 18:43
13 lines
2275 bytes
2275 bytes
Gang--
If you're a VB scripter, you've probably noticed that many of the AppleScript threads in this forum have included text references for ranges of text, such as:
set myRange to object reference of text from character 20 to character 47 of story 1
How can you do this in Visual Basic? Thanks to the amazing Jonathan Brown (who slipped this in either late in ID 2.0 development or during ID 2.01 development--we're not sure which), we have the ItemByRange reference method, as shown in the following example:
Dim myInDesign As InDesign.Application Set myInDesign = CreateObject("InDesign.Application.2.0") myInDesign.FindPreferences = idNothing myInDesign.ChangePreferences = idNothing Set myDocument = myInDesign.Documents.Add Set myTextFrame = myDocument.Pages.Item(1).TextFrames.Add Set myPage = myDocument.Pages.Item(1) myX1 = myPage.MarginPreferences.MarginLeft myY1 = myPage.MarginPreferences.MarginTop myX2 = myDocument.DocumentPreferences.PageWidth - myPage.MarginPreferences.MarginRight myY2 = myDocument.DocumentPreferences.PageHeight - myPage.MarginPreferences.MarginBottom myTextFrame.GeometricBounds = Array(myY1, myX1, myY2, myX2) myTextFrame.TextContents = idPlaceholderText Set myCharStyle = myDocument.CharStyles.Add myCharStyle.FillColor = myDocument.Colors.Item(myDocument.Colors.Count) Set myStory = myDocument.Stories.Item(1) Set myRange = myStory.Characters.ItemByRange(myStory.Characters.Item(6), myStory.Characters.Item(29)).Item(1) myRange.CharacterStyle = myCharStyle
Pretty cool, huh? Thanks, Jonathan!
Ole
Technical Details
Message-ID:
<ef91c3a.-1@WebX.aaQKaf7vad4>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-04!supernews.com!news-xfer2.newshosting.com!nntp-relay.ihug.net!ihug.co.nz!newsfeed.media.kyoto-u.ac.jp!newsfeed01.sul.t-online.de!t-online.de!WebXShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f939a,d60d2db01dfd5612,start X-Google-Attributes: gidf939a,public X-Google-ArrivalTime: 2002-06-13 12:08:36 PST From: "Olav Kvern" <okvern@adobe.com> Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-04!supernews.com!news-xfer2.newshosting.com!nntp-relay.ihug.net!ihug.co.nz!newsfeed.media.kyoto-u.ac.jp!newsfeed01.sul.t-online.de!t-online.de!WebX Newsgroups: adobe.scripting.indesign Subject: VB Getting an arbitrary range of text Message-ID: <ef91c3a.-1@WebX.aaQKaf7vad4> Date: Thu, 13 Jun 2002 11:43:00 -0700 Lines: 41 MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8bit