Reply to topic  [ 5 posts ] 
How to pause macro when menu dialog is opened? 
Author Message

Joined: 2009-02-17 17:44:12
Posts: 37
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


2013-03-29 23:32:34
Profile
User avatar

Joined: 2007-02-07 00:58:12
Posts: 876
Location: Japan
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.

_________________
philip


2013-04-01 09:02:57
Profile
User avatar

Joined: 2007-02-07 00:58:12
Posts: 876
Location: Japan
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


2013-04-01 10:47:03
Profile

Joined: 2009-02-17 17:44:12
Posts: 37
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


2013-04-01 16:08:06
Profile
Official Nisus Person
User avatar

Joined: 2002-07-11 17:14:10
Posts: 4251
Location: San Diego, CA
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.


2013-07-02 10:18:12
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 5 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software