Help needed with Show Find Results

Get help using and writing Nisus Writer Pro macros.
Post Reply
ThosGreen
Posts: 16
Joined: 2021-09-15 03:28:09

Help needed with Show Find Results

Post by ThosGreen »

I want to list all words in a specified character style. The manual gives search examples that open a window with a list of found terms, but I can't make that work for me. It's obviously something simple I haven't understood. My macro:

Code: Select all

$doc = Document.active
$found = Hash.new
Find All "(AnyWord)", 'eau'
Show Find Results $found, "All Glossary  Terms"
'AnyWord' is a PowerFind bubble from the Find/Replace dialog and I've applied the relevant character styling to it. The macro finds all the terms successfully but finishes by showing a window saying '0 matches in 0 documents'.

How should I use the Show Find Results?
User avatar
phspaelti
Posts: 1313
Joined: 2007-02-07 00:58:12
Location: Japan

Re: Help needed with Show Find Results

Post by phspaelti »

The problem is that your hash $found does not contain anything. You initialize it. But then you do the Find command in the GUI, which isn't going to have any effect on $found.

You can get the effect that you (perhaps) intend, by changing the code as follows:

Code: Select all

$doc = Document.active
$found = $doc.text.findAll "(AnyWord)", 'eau'
Show Find Results $found, "All Glossary  Terms"
The Show Find Results command is pretty cool, but it takes some getting used to. Basically the argument needs to be a collection object containing TextSelection objects. It can be a 'simple' collection like in this example, or it can be a 'grouped' collection (using a Hash) where each group is labelled in some way; by document, or some other grouping.

A TextSelection, by the way, is just what it sounds like. It's an object that has two parts: a text object (for example the text of your document) and a range object (which specfies which characters of your document text are selected). You can get a TextSelection object (or a whole array of them) either using Selection commands, or using Find commands.

Hope this is not TMI, but feel free to ask if you need more help.
philip
User avatar
martin
Official Nisus Person
Posts: 5227
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: Help needed with Show Find Results

Post by martin »

ThosGreen wrote: 2023-03-16 03:25:36 How should I use the Show Find Results?
Philip gave a nice explanation on how to use Show Find Results, but for your specific example you don't actually need to bother with all that. Instead just use the "V" option for your find/replace command, which shows a find results list window automatically. With that your whole macro can be a single line:

Code: Select all

Find All "(AnyWord)", 'eauV'
.
Post Reply