nisus.com
https://www.nisus.com/forum/

Insert commands in macro
https://www.nisus.com/forum/viewtopic.php?f=17&t=3895
Page 1 of 1

Author:  Elisa [ 2010-09-08 07:23:04 ]
Post subject:  Insert commands in macro

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

Author:  Kino [ 2010-09-08 09:19:41 ]
Post subject:  Re: Insert commands in macro

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:
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:
: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 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.

Author:  martin [ 2010-09-08 12:34:57 ]
Post subject:  Re: Insert commands in macro

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:
: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.
Quote:
Also, if the last component of a menu path is unique, you can simplify the macro into something like
Code:
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:
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.

Author:  Elisa [ 2010-09-10 03:02:24 ]
Post subject:  Re: Insert commands in macro

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

Elisa

Page 1 of 1 All times are UTC - 8 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/