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

Undo a macro
https://www.nisus.com/forum/viewtopic.php?f=17&t=3522
Page 1 of 1

Author:  loulesko [ 2009-09-01 12:02:35 ]
Post subject:  Undo a macro

Hi there,

I have a macro that does a lot of text changes and ends with a select all - copy - select end to copy the changes to the clipboard. I then want to undo the changes, but the follwoing commands are not working in the macro. Edit:Undo or Undo or Edit:Undo Macro- but it works fine when I choose Undo from the edit menu.

Thanks
Lou

Author:  martin [ 2009-09-01 13:41:17 ]
Post subject:  Re: Undo a macro

Hi Lou- the "Undo" command inside a macro itself is treated differently than normal. NWP assumes you only want to undo the last step of the macro. For example, consider this macro:
Code:
Bold
Italic
Undo

The "Undo" command only undoes the "Italic" command, and thus this macro only changes whether text is bold or not.

On the other hand, once a macro has been completed, all changes it made are grouped to be a single action. That is, choosing "Undo" from the menu will undo all changes made by the macro.

Currently there's no single command that would allow you to undo all changes made by the macro from inside the macro. There's two ways you might work around this. The first is to execute the "Undo" command in your macro as many times as you need, eg:
Code:
Bold
Italic
Undo
Undo

If your macro does many things this may be error prone, but you might shorten it up like so:
Code:
Bold
Italic

$undoCount = 2
While $undoCount > 0
    Undo
    $undoCount -= 1
End

That may not be terribly efficient. It might be better to work on a copy of the active document, like so:
Code:
$doc = Document.active
$doc = $doc.copy
$doc.clearAndDisableUndoHistory # for efficiency, also allows closing doc at the end without any warning
# do whatever you want
$doc.close

Author:  loulesko [ 2009-09-01 16:19:51 ]
Post subject:  Re: Undo a macro

That last solution creating a copy is brilliant and does exactly what I need.

Many thanks.
Lou

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