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

How to pause macro when menu dialog is opened?
https://www.nisus.com/forum/viewtopic.php?f=17&t=5309
Page 1 of 1

Author:  tomoyuki-kosaka [ 2013-03-29 23:32:34 ]
Post subject:  How to pause macro when menu dialog is opened?

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

Author:  phspaelti [ 2013-04-01 09:02:57 ]
Post subject:  Re: How to pause macro when menu dialog is opened?

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

Author:  phspaelti [ 2013-04-01 10:47:03 ]
Post subject:  Re: How to pause macro when menu dialog is opened?

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.

Author:  tomoyuki-kosaka [ 2013-04-01 16:08:06 ]
Post subject:  Re: How to pause macro when menu dialog is opened?

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

Author:  martin [ 2013-07-02 10:18:12 ]
Post subject:  Re: How to pause macro when menu dialog is opened?

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.

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