How to pause macro when menu dialog is opened?

Get help using and writing Nisus Writer Pro macros.
Post Reply
tomoyuki-kosaka
Posts: 37
Joined: 2009-02-17 17:44:12

How to pause macro when menu dialog is opened?

Post by tomoyuki-kosaka » 2013-03-29 23:32:34

Now I'm trying to make the macro script for to re-attach cross-reference to the text converted cross-reference by "convert to fixed content" command.

I usually use List style as "Figure 1" and use that for Cross-reference in the text. Its good way for manage the figure numbers in the manuscript. I don't need to care about the order of figures. However, when I convert it to fixed one and pass to someone who will modify the text. Then, it is hard to re-attach these cross references to the latest manuscript.
You know if I can use cross-reference with my colleagues, there are no problem. But, sometimes plane text is more favorable.

So, I tried to write a macro script. This is my script.

Code: Select all

$doc = Document.active
$list_styles = $doc.listStyles
$message = 'Which is list style re-converted?'
$selected_style = Prompt Options $message, "", "Choose", $list_styles
$selected_style_name = $selected_style.name

Select Document End
While Select Previous List Item
  $menu_state = Menu State ":Format:Lists:$selected_style_name"
  If $menu_state
    $sel = $doc.textSelection
    $num = $sel.substring
    Begin Perl
      chop $num;
    End
    Prompt $num
    while Find $num
      $menu_state = Menu State ":Format:Lists:$selected_style_name"
      If $menu_state == 1
        Break
      Else
        Menu ":Insert:Cross-reference..."
        #Prompt "Inserted Cross-reference link for $num"
      End
    End
  End
End
I insert "Prompt" for to wait until selection in menu ":Insert:Cross-reference..." dialog, however it does not work well.
I cannot find out cross-reference insertion command in macro reference.
Does anyone know good way for accomplish this?

Kosaka

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

Re: How to pause macro when menu dialog is opened?

Post by phspaelti » 2013-04-01 09:02:57

Hello Kosaka,

I believe Martin has said that the Cross-Reference interface cannot be scripted. As a workaround that may work you could try the following:

Code: Select all

Menu ":Insert:Cross-reference..."
Send Text $num
Press Button “Insert”
This code works via the user interface. With the ":Insert:Cross-reference..." menu in the front, the command "Send Text $num" will "type" the number of the cross-reference, and this should select the cross-reference. The "Press Button" command will then insert the cross-reference. I have not tested this very much, but it has worked for me.

Note however that the macro will be a bit unstable. It will only work right, if the cross-reference menu has been set to show the list items. Changing that with a macro is not possible, I think.
philip

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

Re: How to pause macro when menu dialog is opened?

Post by phspaelti » 2013-04-01 10:47:03

I seem to be in deja-vu land, but I can't find the previous discussion.

My earlier suggestion seems to work, for multiple cross-references, if you keep the "prompt $num" instruction. This has something to do with the updating of the GUI while a macro is running. Once you take the "prompt" line out the cross-reference remains "stuck" on the first cross-reference it selected. Martin once told me a better way to fix this, but I forgot.
philip

tomoyuki-kosaka
Posts: 37
Joined: 2009-02-17 17:44:12

Re: How to pause macro when menu dialog is opened?

Post by tomoyuki-kosaka » 2013-04-01 16:08:06

Thank you phspaelti!
Your code work as you mentioned and I expected.
"Send Text" is a good solution for me.

If we can handle menu command more flexibly in macro, NWP macro will be comfortable.
I hope coming version NWP includes that solution or cross-reference treatable commands.

Anyway, thanks again.

Kosaka

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

Re: How to pause macro when menu dialog is opened?

Post by martin » 2013-07-02 10:18:12

Philip is right, using the macro language to manipulate the insert cross-references dialog like this is not very stable. But we'll consider this thread a feature request to enhance the macro language to allow for a clean way of inserting new cross-refs.

Post Reply