Article View: adobe.scripting.indesign
Article #19844Re: Mapping Character Styles to XMLTags
From: Olav Kvern
Date: Mon, 18 Nov 2002 21:08
Date: Mon, 18 Nov 2002 21:08
52 lines
2652 bytes
2652 bytes
amjb--
Try something like this:
tell application "InDesign 2.0.1"
set myDocument to active document
if count XML Elements of myDocument > 0 then
repeat with myCounter from 1 to (count character styles of myDocument)
if name of character style myCounter of myDocument is not "[No character style]" then
my myMapCharStyle(myDocument, name of character style myCounter of myDocument)
end if
end repeat
else
display dialog "Document contains no XML elements."
end if
end tell
--Handler for creating XML Elements from text tagged with a specific character style.
on myMapCharStyle(myDocument, myCharStyleName)
tell application "InDesign 2.0.1"
--Create the XML tag, if necessary.
tell myDocument
try
set myXMLTag to XML Tag myCharStyleName
on error
--XML tag did not exist, so create it.
set myXMLTag to make XML Tag with properties {name:myCharStyleName}
end try
end tell
--Clear the change preferences
set change preferences to nothing
--Add the target character style to the find preferences
set applied character style of find preferences to character style myCharStyleName of myDocument
set myFoundItems to search myDocument for ""
--Iterate backwards through the list of found items. Why? The items are all text references from character x to y--
--XML tag markers count as characters, so iterating forwards throws the character count references off as you tag the text.
repeat with myCounter from (count myFoundItems) to 1 by -1
set myItem to item myCounter of myFoundItems
--get a reference to the XML element containing the item
set myXMLStory to item 1 of associated XML elements of myItem
tell myXMLStory to make XML Element with properties {markup tag:myXMLTag, associated object:myItem}
end repeat
end tell
end myMapCharStyle
Thanks,
Ole
Technical Details
Message-ID:
<1de6a436.0@WebX.la2eafNXanI>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!sn-xit-06!sn-xit-08!supernews.com!news.tele.dk!news.tele.dk!small.news.tele.dk!eusc.inter.net!newsfeed01.sul.t-online.de!t-online.de!WebXReferences:
<1de6a436.-1@WebX.la2eafNXanI>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f939a,1d3166bf8ca06c6 X-Google-Attributes: gidf939a,public X-Google-ArrivalTime: 2002-11-18 14:02:07 PST From: "Olav Kvern" <okvern@adobe.com> Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!sn-xit-06!sn-xit-08!supernews.com!news.tele.dk!news.tele.dk!small.news.tele.dk!eusc.inter.net!newsfeed01.sul.t-online.de!t-online.de!WebX Newsgroups: adobe.scripting.indesign Subject: Re: Mapping Character Styles to XMLTags Message-ID: <1de6a436.0@WebX.la2eafNXanI> Date: Mon, 18 Nov 2002 13:08:48 -0800 References: <1de6a436.-1@WebX.la2eafNXanI> Lines: 56 MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8bit