🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: adobe.scripting.indesign
Article #18564

Search broken in 2.0.2?

#18564
From: adamcoop
Date: Tue, 11 Mar 2003 22:06
95 lines
4669 bytes
I'm still looking for a way to successfully apply character styles to XML tags - I found a great script by Ole to do this, but it errors when searching for ""
i.e. The script does the following: 

      set myFoundItems to search myDocument for "" And when it gets to the next
      reference of myFoundItems, says 'the variable myFoundItems is not defined'.





Here's the script in question:

      tell application "InDesign 2.0.2" 	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.2"
      		--Create the XML tag, if necessary.
      		tell myDocument
      			--Replace any spaces in the character style name with underscores.
      			set myTagName to my replace_chars(myCharStyleName, " ", "_")
      			try
      				set myXMLTag to XML Tag myTagName
      			on error
      				--XML tag did not exist, so create it.
      				set myXMLTag to make XML Tag with properties {name:myTagName}
      			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
			--Check for XML tag markers in the found item.
			if contents of character 1 of myItem is "<FEFF>" or contents of character -1 of myItem is "<FEFF>" then
				set myItem to my myStripMarkers(myItem)
			end if
			--get a reference to the XML element containing the item
			set myXMLElement to item 1 of associated XML elements of myItem
			tell myXMLElement to make XML Element with properties {markup tag:myXMLTag, associated object:myItem}
		end repeat
	end tell
end myMapCharStyle

--Handler for stripping the XML element marker charactes out of a text object.
on myStripMarkers(myItem)
	tell application "InDesign 2.0.2"
		repeat while contents of character 1 of myItem is "<FEFF>"
			set myStart to index of character 1 of myItem
			set myEnd to index of character -1 of myItem
			set myItem to object reference of characters (myStart + 1) through myEnd of parent story of myItem
		end repeat
		repeat while contents of character -1 of myItem is "<FEFF>"
			set myStart to index of character 1 of myItem
			set myEnd to index of character -1 of myItem
			set myItem to object reference of characters myStart through (myEnd - 1) of parent story of myItem
		end repeat
	end tell
	return myItem
end myStripMarkers

--Find/change routine from Apple's AppleScript Guidebook
--module "Essential sub-routines."
on replace_chars(this_text, search_string, replacement_string)
	set AppleScript's text item delimiters to the search_string
	set the item_list to every text item of this_text
	set AppleScript's text item delimiters to the replacement_string
	set this_text to the item_list as string
	set AppleScript's text item delimiters to ""
	return this_text
end replace_chars
Technical Details
Message-ID: <1de83fbc.-1@WebX.la2eafNXanI>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-01!sn-xit-09!supernews.com!news.maxwell.syr.edu!nntp.infostrada.it!newsfeed01.sul.t-online.de!t-online.de!WebX

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f939a,7731eb9b6068222c,start
X-Google-Attributes: gidf939a,public
X-Google-ArrivalTime: 2003-03-11 14:07:49 PST
From: adamcoop <adam.c@ncprint.com.au>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-01!sn-xit-09!supernews.com!news.maxwell.syr.edu!nntp.infostrada.it!newsfeed01.sul.t-online.de!t-online.de!WebX
Newsgroups: adobe.scripting.indesign
Subject: Search broken in 2.0.2?
Message-ID: <1de83fbc.-1@WebX.la2eafNXanI>
Date: Tue, 11 Mar 2003 14:06:34 -0800
Lines: 97
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit