🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: adobe.scripting.indesign
Article #19031

Re: detect invisible markup characters

#19031
From: Olav Kvern
Date: Tue, 28 Jan 2003 20:49
72 lines
3275 bytes
Ralf--

XML markup tags are Unicode <FEFF>. Here's how to find the Unicode value of a selected character.



Private Sub Command1_Click() 
Rem Get Unicode String 
Dim myInDesign As InDesign.Application 
Set myInDesign = CreateObject("InDesign.Application.2.0") 
If myInDesign.Documents.Count > 0 Then 
Set myDocument = myInDesign.ActiveDocument 
Set mySelection = myInDesign.Selection 
    If mySelection.Count > 0 Then 
        Set myText = mySelection.Item(1) 
        myUnicodeString = myGetUnicodeString(myText) 
        MsgBox "The selected character is Unicode " & myUnicodeString 
    End If 
End If 
End Sub 
Private Function myGetUnicodeString(myText) 
Rem Get Unicode String 
myString = "" 
Set myCharacter = myText.Characters.ItemByRange(myText.Characters.Item(1), myText.Characters.Item(myText.Characters.Count)).Item(1) 
myContents = myCharacter.TextContents 
For myCounter = 1 To Len(myContents) 
    myCharacter = Mid(myContents, myCounter, 1) 
    If AscW(myCharacter) < 0 Or AscW(myCharacter) > 255 Then 
        myString = myString & "<" & CStr(Hex(AscW(myCharacter))) & ">" 
    Else 
        myPadString = "" 
        myLength = 4 - Len(CStr(Hex(AscW(myCharacter)))) 
        For myPadCounter = 1 To myLength 
            myPadString = myPadString & "0" 
        Next 
        myString = myString & "<" & myPadString & Hex(AscW(myCharacter)) & ">" 
    End If 
Next 
myGetUnicodeString = myString 
End Function 




In general, you can test for InDesign's special characters by getting the typename of the TextContents property--if it's a Long, you know you've got one of InDesign's special characters. This doesn't work for the XML markup character, but it might come in handy in other situations.



Private Sub Command1_Click() 
Rem Is the selected character an enum? 
Dim myInDesign As InDesign.Application 
Set myInDesign = CreateObject("InDesign.Application.2.0") 
If myInDesign.Documents.Count > 0 Then 
Set myDocument = myInDesign.ActiveDocument 
Set mySelection = myInDesign.Selection 
    If mySelection.Count > 0 Then 
        Set myText = mySelection.Item(1) 
        Set myCharacter = myText.Characters.Item(1) 
        If TypeName(myCharacter.TextContents) = "Long" Then 
            MsgBox "Character is one of InDesign's special characters." 
        Else 
            MsgBox "Character is a normal string." 
        End If 
    End If 
End If 




Thanks,

Ole
Technical Details
Message-ID: <1de78e06.0@WebX.la2eafNXanI>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-08!supernews.com!64.152.100.70.MISMATCH!sjc70.webusenet.com!news.webusenet.com!iad-peer.news.verio.net!news.verio.net!news.maxwell.syr.edu!nntp.infostrada.it!newsfeed01.sul.t-online.de!t-online.de!WebX
References: <1de78e06.-1@WebX.la2eafNXanI>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f939a,fc058cbf7f57ecfa
X-Google-Attributes: gidf939a,public
X-Google-ArrivalTime: 2003-01-28 13:07:55 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-08!supernews.com!64.152.100.70.MISMATCH!sjc70.webusenet.com!news.webusenet.com!iad-peer.news.verio.net!news.verio.net!news.maxwell.syr.edu!nntp.infostrada.it!newsfeed01.sul.t-online.de!t-online.de!WebX
Newsgroups: adobe.scripting.indesign
Subject: Re: detect invisible markup characters
Message-ID: <1de78e06.0@WebX.la2eafNXanI>
Date: Tue, 28 Jan 2003 12:49:43 -0800
References: <1de78e06.-1@WebX.la2eafNXanI>
Lines: 70
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit