Macro and Powerfind

Get help using and writing Nisus Writer Pro macros.
Post Reply
dougelrsystems
Posts: 4
Joined: 2020-08-31 16:45:11

Macro and Powerfind

Post by dougelrsystems »

I apologize for this very basic question but I have searched a LOT of the topics here and can't find what I need. It seems that I need to know something I can't find before I can get started.

I need someone to give me the really basic beginning of how to write and run a macro to do the following:

Take this Powerfind expression: (Any Double Quote)Text4=(AnyWord)(Any Double Quote)(Return)
This turns into: ["\u201C\u201D\u201E\u201F]Text4=(?:\b\w+\b)["\u201C\u201D\u201E\u201F]\n
when I select Powerfind regex but How do I make a find and replace macro with that? I have tried a lot of things but not the one correct thing.

I have gotten a Perl error with every combination I try.

And I will want to replace with "Time1=20"

Thanks in advance.
adryan
Posts: 561
Joined: 2014-02-08 12:57:03
Location: Australia

Re: Macro and Powerfind

Post by adryan »

G'day, dougelrsystems et al

Nisus Writer will create the macro for you. See "Create a macro from Find and Replace expressions" on Page 449 of the Nisus Writer User Guide (under the Help menu). Once you have your macro document, you can edit it as you see fit.

Hope this helps.

Cheers,
Adrian
MacBook Pro (M1 Pro, 2021)
macOS Ventura
Nisus Writer user since 1996
User avatar
phspaelti
Posts: 1313
Joined: 2007-02-07 00:58:12
Location: Japan

Re: Macro and Powerfind

Post by phspaelti »

Hello Doug, and welcome to Nisus.
Adrian has already pointed you to a useful section in the manual. I just thought I'd a few more pointers.

In case it wasn't clear, there is no need to switch to PowerFind Pro to turn a find/replace command into a macro. You can macroize the expression in the PowerFind format.

You refer to "perl" errors. In order to create a macro which does a find/replace action, there is no need to use perl. Perl macros certainly can do find/replace on your document, but the whole syntax for this is different in a variety of ways. PowerFind Pro expressions do have a lot of overlap with perl syntax, but some things are still different. In general, in the current iteration of Nisus, there is really no need to use perl, and no advantage either.

The expression you describe would look like this as a Nisus macro (PowerFind Pro style):

Code: Select all

Find and Replace @s#["\u201C\u201D\u201E\u201F]Text4=(?:\b\w+\b)["\u201C\u201D\u201E\u201F]\n#, @s#"Time1=20"#, 'Ea'
Though I do have a few questions:
  • Do you really want to delete the final carriage return? If not maybe better to use "End of Paragraph" instead.
  • Are you looking to regularize the quotes with this?
Perhaps the following is helpful?
viewtopic.php?p=31733#p31733
philip
dougelrsystems
Posts: 4
Joined: 2020-08-31 16:45:11

Re: Macro and Powerfind

Post by dougelrsystems »

Thank you both.

It's actually welcome back to Nisus. I started with version 1 a very very long time ago but I wasn't really doing any word processing for a long time so I forgot about it until I needed to do a LARGE find and replace task with over 2000 files.

The problem was I was using Express instead of pro, that was most of my problem. Now that I upgraded to Pro, this is doing what I wanted.

I do have one other question I can't find the answer to. Can I do a find until I get to a certain character? For example:

"Text28=ICU - released 2019-04-24, updated 2019-11-19.

Because they are most effective when applied with a longer than standard dwell, each frequency in this preset runs for five minutes, and should be adjuncted by using the overnight version as well. Use this daytime preset twice daily, plus the overnight preset, for 6-7 days, then evaluate. Alternatively, use this preset twice daily, plus the remote version, for 10-14 days. Be sure to run the IC Detox & Support preset remotely on a second generator, and hydrate well.

https://www.xxxicu.com

"
"Text29=0"


I would like to find everything from "Text28... to the double quote just before "Text 29... and just delete it. Is there a find or capture until I get to a certain character option??

Thanks again!

Doug
User avatar
phspaelti
Posts: 1313
Joined: 2007-02-07 00:58:12
Location: Japan

Re: Macro and Powerfind

Post by phspaelti »

dougelrsystems wrote: 2020-09-02 19:40:43
I would like to find everything from "Text28... to the double quote just before "Text 29... and just delete it. Is there a find or capture until I get to a certain character option??
Look in the Match menu (of the gear menu in the Find dialog) for Followed by
So you can write:

Code: Select all

Find and Replace @String<"Text28\X*?(?="Text29)>, "", 'E-i' 
philip
dougelrsystems
Posts: 4
Joined: 2020-08-31 16:45:11

Re: Macro and Powerfind

Post by dougelrsystems »

That works perfectly, thank you! It solves my current problem.

As I don't understand regex, that is really Greek to me. Can that be done with powerfind?

Again, thank you!
User avatar
phspaelti
Posts: 1313
Joined: 2007-02-07 00:58:12
Location: Japan

Re: Macro and Powerfind

Post by phspaelti »

Screen Shot 2020-09-03 at 14.45.jpg
Screen Shot 2020-09-03 at 14.45.jpg (110.13 KiB) Viewed 15360 times
philip
dougelrsystems
Posts: 4
Joined: 2020-08-31 16:45:11

Re: Macro and Powerfind

Post by dougelrsystems »

Thank you, the 0+Shortest was the part I didn't realize. For clarity for anyone else in the future, the attached image has the whole macro line.

I have only one more question before I can fly on my own. (I have over 2,000 files to process.)

I would like to capture some numbers from the files and then at the end of my searches and replacing, bring up a prompt dialog with a few of the values I found.

I have tried doing this:
The file contains this line:

"Text14=33"

This is my macro:

$Duty = 2
Prompt "$Duty" #This prompts with the string "2"

$Duty = Find "(Any Double Quote)Text14=(Capture()(AnyDigit)(1+)())(Any Double Quote)(Return)", 'ea'
Prompt "$Duty" #This prompts with the string "1"


Is there a way with Powerfind to find some text and assign it to a variable that I can later use in either a prompt or a new find and replace command?

From what I have gathered, the Capture() command ONLY works within the confines of the current Find and Replace command which is why I'm trying to put the value into a variable.
Attachments
Screen Shot 2020-09-03 at 12.41.10 AM.png
Screen Shot 2020-09-03 at 12.41.10 AM.png (18.03 KiB) Viewed 15352 times
User avatar
phspaelti
Posts: 1313
Joined: 2007-02-07 00:58:12
Location: Japan

Re: Macro and Powerfind

Post by phspaelti »

dougelrsystems wrote: 2020-09-03 00:02:03 Is there a way with Powerfind to find some text and assign it to a variable that I can later use in either a prompt or a new find and replace command?
Yes.

First a bit about using $variable = … with find expressions. Note that you are using a 'a' option with your expression. This makes your expression a "Find All" search and will potentially return a lot of hits, not just one. With the Find command assigning the result to a variable will give you the number of hits. This is convenient for embedding the Find command in a test:

Code: Select all

if Find …
    # do some stuff
end
If the find is successful, it will do stuff, otherwise it will skip that part.

Now to the bit about keeping matched stuff from a search. For this you will need to give up on the 'a' option, since otherwise the search might find many things and then the matched bit will not have a unique match. So do this instead:

Code: Select all

Find "(Any Double Quote)Text14=(Capture()(AnyDigit)(1+)())(Any Double Quote)(Return)", 'e¢'
Prompt $1
So the option you will need is '¢' and then you can refer to the matched bits using variable names: So $1 for the first matched bit, $2 for the second, etc.

Instead of the '¢' option you could use '$' as well. The difference is that '$' will return formatted text in the variable while '¢' will return a string.

One more important point: If you want to do another Find before using the found bit you will need to store it somewhere else, as the $1 variable is reset on each find command. PowerFind Pro actually allows you to give more meaningful names to the found bits directly, but I can't see any way to that using PowerFind.
philip
Post Reply