displaying the number of found text

Get help using and writing Nisus Writer Pro macros.
Post Reply
js
Posts: 229
Joined: 2007-04-12 14:59:36

displaying the number of found text

Post by js » 2009-01-17 02:34:48

Can the number of found text be caught in a macro? F.e. if yoy are only interested in how many times a selected textstring appears in the document, how would a macro look like that display number of found text, not leaving the actual caret postion?

User avatar
martin
Official Nisus Person
Posts: 4289
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: displaying the number of found text

Post by martin » 2009-01-19 14:57:42

That is something you can do:

Code: Select all

# save selection
$doc = Document.active
$selections = $doc.textSelections

# count found instances
$count = Find 'red', 'a'

# restore selection and prompt
$doc.setSelections($selections)
Prompt "Found $count instances."
I actually would have thought you could you use the "S" Find option, which means preserve the selection, but that only works for Replace commands. I'll have to file that as a bug. In the meantime, you could use the super secret "f" option, which would shorten the macro considerably:

Code: Select all

$count = Find 'red', 'af'
Prompt "Found $count instances."
This would also run quicker, if efficiency is important. Unfortunately the "f" option may change its letter at some point.

js
Posts: 229
Joined: 2007-04-12 14:59:36

Re: displaying the number of found text

Post by js » 2009-01-20 08:29:08

Ever so happy to discover a little secret. If "f" changes we will change with it. Thanks for helping.

User avatar
martin
Official Nisus Person
Posts: 4289
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: displaying the number of found text

Post by martin » 2009-01-20 13:40:16

Glad to help! The next update will have the "S" option fixed for Find commands, so you can simply use "S" instead of "f" and it will work as intended.

Post Reply