Skip to main content
Inspiring
July 28, 2021
Answered

Trigger Illustrator menu item "Undo" from plugin.

  • July 28, 2021
  • 1 reply
  • 738 views

Hello Together,

the task I want to do sounds fairly simple:

I want Illustrator to do a global "Undo" operation, triggered by my plugin!

I want the same result as if a user clicks in the Illustrator menu on "File-> Revert" (in german it is "Bearbeiten-> Rückgängig).

 

Unfortunately, I could not find access to the native Illustrator menu items so far.

 

I tried using the function sAIUndo->UndoChanges in my plugin, but it does not work at all.

In addition to that, the function sAIUndo->CountTransactions always returns "0" and the function sAIAppContext->DoesAppContextExist always returns "false".

 

Nevertheless, if I click in the Illustrator menu on "File-> Revert", everything works fine and the last changes are reverted.

Which suite and function do I need to use in order to get the same result?

Thank you very much in advance,

Fabian Taubitz

 

This topic has been closed for replies.
Correct answer MilosR

Hello again,

I was too hasty when I said it would be good enough for my purpose. 😉

Although the undo works, the redo seems to be the problem now.

When I use sAIUndo->RevertAndForgetLastTransaction there is no redo available afterwards, as intended by this function.

But I would like to have the same behavior as using the menu entry "File-> Revert", which provides a redo option.

So, what is needed to get the same redo option?

Thanks again in advance,

Fabian Taubitz


For Revert you can use AIMenuSuite::InvokeMenuAction. Iterate through all commands to find command id for command with commandStr ==  kRevertCommandStr (or use AICommandManagerSuite::GetCommandIDFromName). You can use this method for undo and redo too, use kUndoCommandStr and kRedoCommandStr

1 reply

MilosR
Inspiring
July 29, 2021

Did you create context using  AppContext. Just try to add following line:

 

AppContext appContext(gPlugin->GetPluginRef());

 

owitaAuthor
Inspiring
July 29, 2021

Thank you very much for the fast answer. 🙂

Using this line of code definitely had an impact.

 

Now the function sAIAppContext->DoesAppContextExist returns "true" and the function sAIUndo->CountTransactions returns the number of "undoable" transactions, made beforehand. So far so good.

Unfortunately the function sAIUndo->UndoChanges still does not work. No changes in Illustrator and no changes in the transactions.

But when I use the function sAIUndo->RevertAndForgetLastTransaction instead, it works and the last change is reverted. Furthermore, the transaction-count is reduced by one.

 

This is good enough for my purposes so far, but I am still confused why the function sAIUndo->UndoChanges is not changing anything.

 

Best Regards,

Fabian Taubitz

 

 

owitaAuthor
Inspiring
July 29, 2021

Hello again,

I was too hasty when I said it would be good enough for my purpose. 😉

Although the undo works, the redo seems to be the problem now.

When I use sAIUndo->RevertAndForgetLastTransaction there is no redo available afterwards, as intended by this function.

But I would like to have the same behavior as using the menu entry "File-> Revert", which provides a redo option.

So, what is needed to get the same redo option?

Thanks again in advance,

Fabian Taubitz