> On Nov 5, 2015, at 9:42 , Nobumi Iyanaga <[log in to unmask]> wrote:
> 
> This works very well, but as I had failed to communicate the exact purpose of the macro, he wrote one which finds and selects only "the next occurrence" of a word indexed under a certain topic.
> 
> Wouldn't it be possible to modify this macro so that it would finds and selects *all* the occurrences of words, etc. indexed under a certain topic? (I ask this to this mailing list because Martin says that he is absent for some days, and I need this macro very soon...)

Here is a modified version of Martin’s macro, which will find all in the document. Note that it will also find across different text objects, which will allow it to find in the main document, as well as in table cells, and notes, etc.

# Find All In Index Topic
# This macro searches through all indexing topics in the document, ie: the "index as" text.
# It will select all marked text whose indexing contains the given search.
# Matching is case insensitive.
# Martin Wierschin 15-11-02
# Modified by P. Spaelti 15-11-05

$doc = Document.active
$indexName = Active Text Index Name

# ask user what to search for, defaulting to the last search value
$registry = Registry.applicationRegistry
$registryKey = "com.nisus.findIndexTopic.searchString"
$findWhat = $registry.loadValueWithName($registryKey)
$findWhat = Prompt Input "Search for what indexing topics?", "", "Search", $findWhat
$registry.saveValueWithName($findWhat, $registryKey)

$sels = Array.new

foreach $text in $doc.allTexts
	$loc = 0
	While $loc < $text.length
		$attr = $text.attributesAtIndex($loc)
		$range = $text.rangeOfAttributesAtIndex($loc)
		$loc = $range.bound
		
		$topicsArray = $attr.textIndexTopicsForStyleName($indexName)
		If Defined $topicsArray
			# check for match
			$topicsStr = ""
			ForEach $topics in $topicsArray
				If 0 == $topics.count
					# auto topic
					$topicsStr &= $text.substringInRange($range)
				Else
					$topicsStr &= Cast to String $topics
				End
				$topicsStr &= "\n"
			End
			
			If $topicsStr.containsString($findWhat, 'i')
				$sels.push TextSelection.new($text, $range)
			End
		End
	End
End

if $sels.count
	$doc.setSelection $sels
else
	Prompt "No matching indexing topics found.", "Indexing for '$indexName' does not contain: $findWhat"
end
# end of macro #



Philip Spaelti
[log in to unmask]