Insert commands in macro

Get help using and writing Nisus Writer Pro macros.
Post Reply
Elisa
Posts: 2
Joined: 2010-09-03 06:26:30

Insert commands in macro

Post by Elisa »

Hi,
I'm learning to write macros by coping and editing existing files. But now I don't know how to proceed. How can I insert commands in my macro which I usually carry out by mouse?
For example "Select All > Format > Parapgraph Styles > Remove style"

Thanks for every help,
Elisa
Kino
Posts: 400
Joined: 2008-05-17 04:02:32

Re: Insert commands in macro

Post by Kino »

Welcome to the forum!
Elisa wrote:For example "Select All > Format > Parapgraph Styles > Remove style"
You can write a macro just by listing menu commands (or menu command paths) in the right order. I think you mean “Select All” in Paragraph Style menu in the status bar. Unfortunately there is no means to call such a command in a macro but its menu command equivalent does exist. So your macro would be . . .

Code: Select all

Menu ':Format:Paragraph Style:Select All Style'
Menu ':Format:Paragraph Style:Remove Style'
It is not necessary to use the syntax Menu '<menu path>'. Just <menu path> works. So you can reduce the macro to . . .

Code: Select all

:Format:Paragraph Style:Select All Style
:Format:Paragraph Style:Remove Style
In my understanding, the former (Menu '<menu path>') is faster, but I’m too lazy to try a benchmark test.
Also, if the last component of a menu path is unique, you can simplify the macro into something like

Code: Select all

Select All Style
Remove Style
However, Select All Style and Remove Style exist not only under :Format:Paragraph Style but also under :Format:Character Style. So there is no guarantee that commands under the former will be preferred — by NWP — over those under the former. So was I told (perhaps in a dream, ;-) but I have never verified it. Perhaps the physical position/order of homonymous menu commands does matter? Again, I’m too lazy.
User avatar
martin
Official Nisus Person
Posts: 5228
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: Insert commands in macro

Post by martin »

Kino has the right of it, despite his laziness :wink: But truthfully Kino is decidedly dedicated and a hard worker, especially when it comes to helping our users with macros.

Some comments:
Kino wrote:Just <menu path> works. So you can reduce the macro to . . .

Code: Select all

:Format:Paragraph Style:Select All Style
:Format:Paragraph Style:Remove Style
In my understanding, the former (Menu '<menu path>') is faster, but I’m too lazy to try a benchmark test.
It's unlikely there's much of a speed difference between using the command "Menu" and just using the menu path directly. Personally I prefer the former because it's clearer, but either form works just as well.
Also, if the last component of a menu path is unique, you can simplify the macro into something like

Code: Select all

Select All Style
Remove Style
However, Select All Style and Remove Style exist not only under :Format:Paragraph Style but also under :Format:Character Style. So there is no guarantee that commands under the former will be preferred — by NWP — over those under the former. So was I told (perhaps in a dream, ;-) but I have never verified it. Perhaps the physical position/order of homonymous menu commands does matter?
If the menu name is not unique, then the menu Nisus Writer will choose is undefined. One should not rely on any behavior, even if there appears to some consistent rule with respect to how the menus are ordered/positioned. It's best to simply use a full menu path, or if brevity is preferred a path fragment, like:

Code: Select all

Menu 'Character Style:Select All Style'
You may notice that a menu path fragment is not preceded by a ":"- an initial colon is only used if the path is full/complete.
Elisa
Posts: 2
Joined: 2010-09-03 06:26:30

Re: Insert commands in macro

Post by Elisa »

Kino and Martin, you are great!
Thank you so much for your advices. They are very helpfull! :!: :!: :!:

Elisa
Post Reply