🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: adobe.scripting.indesign
Article #8577

Re: I know this should be simple, but how do I get the selected text?

#8577
From: Olav_Kvern
Date: Wed, 11 Oct 2006 17:35
32 lines
1968 bytes
Hi Steve,

Instead, why not use SelectCase to filter the selection? You can see this approach in many of the example scripts that work with text. Something like this:



Set myInDesign = CreateObject("InDesign.Application.CS2") 
If myInDesign.Documents.Count <> 0 Then 
    If myInDesign.Selection.Count = 1 Then 
        Select Case TypeName(myInDesign.Selection.Item(1)) 
            Case "Word", "TextStyleRange", "Line", "Paragraph", "TextColumn", "Text", "TextFrame" 
                Rem Get the contents of the selection. We'll display it in a message box; 
                Rem a real script would do something more interesting with it. 
                myString = myInDesign.Selection.Item(1).Contents 
                MsgBox "The selection contains: " & myString, vbOKOnly 
            Case Else 
                MsgBox "Please select one or more characters and try again." 
        End Select 
    Else 
         MsgBox "Please select some text and try again." 
    End If 
Else 
    MsgBox "No documents are open. Please open a document, select some text, and try again." 
End If



Also, don't use For Each...Next constructions with InDesign objects. To prevent crashes, we limit For Each...Next to 255 iterations. Instead use a For...Next loop with a counter variable.

Thanks,

Ole
Technical Details
Message-ID: <3bc1efe9.1@webcrossing.la2eafNXanI>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!news3.google.com!news2.volia.net!news.ecp.fr!news.stben.net!webcrossing
References: <3bc1efe9.-1@webcrossing.la2eafNXanI>

Show Full Headers
Complete Article Headers
X-Google-Thread: f939a,70d1d670d6ed3210
X-Google-Attributes: gidf939a,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: Olav_Kvern@adobeforums.com
Newsgroups: adobe.scripting.indesign
Subject: Re: I know this should be simple, but how do
 I get the selected text?
Message-ID: <3bc1efe9.1@webcrossing.la2eafNXanI>
Date: Wed, 11 Oct 2006 10:35:55 -0700
References: <3bc1efe9.-1@webcrossing.la2eafNXanI>
Lines: 37
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!news3.google.com!news2.volia.net!news.ecp.fr!news.stben.net!webcrossing