Page 1 of 1
Insert commands in macro
Posted: 2010-09-08 07:23:04
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
Re: Insert commands in macro
Posted: 2010-09-08 09:19:41
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
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.
Re: Insert commands in macro
Posted: 2010-09-08 12:34:57
by martin
Kino has the right of it, despite his laziness
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
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.
Re: Insert commands in macro
Posted: 2010-09-10 03:02:24
by Elisa
Kino and Martin, you are great!
Thank you so much for your advices. They are very helpfull!
Elisa