Skip to main content
wckdtall
Inspiring
July 18, 2023
Answered

Can you suspend history or capture undo in one function in illustrator?

  • July 18, 2023
  • 2 replies
  • 756 views

Just wondering if there is an equivalent to Photoshop:

app.activeDocument.suspendHistory("Heres my undo state", 'main()')

  or InDesign:

app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Heres my Undo State");


While Illustrator does have doScript, it's only for Actions from what I gather. Any googling of suspend history brings up Photoshop implementations. Anything similar for Illustrator?

This topic has been closed for replies.
Correct answer m1b

Hi @wckdtall, the situation with scripting and Undo/Redo in Illustrator is not as good. Here are my observations:

 

1. Most scripting operations will not add to the Undo stack, but some will. I don't know which will or won't but the majority wont in my experience. Therefore the whole script will usually be undo-able in one go. My guess is the less reliant on UI style calls, eg. executeMenuCommand, the more likely the whole script will add just one operation to the Undo stack.

 

2. If you want to have multiple operations added to the Undo stack, you can force it by calling app.redraw() in your script. If you are looping over an array, adding app.redraw() into the loop will give you one undo operation for each iteration.

 

- Mark

2 replies

m1b
Community Expert
m1bCommunity ExpertCorrect answer
Community Expert
July 18, 2023

Hi @wckdtall, the situation with scripting and Undo/Redo in Illustrator is not as good. Here are my observations:

 

1. Most scripting operations will not add to the Undo stack, but some will. I don't know which will or won't but the majority wont in my experience. Therefore the whole script will usually be undo-able in one go. My guess is the less reliant on UI style calls, eg. executeMenuCommand, the more likely the whole script will add just one operation to the Undo stack.

 

2. If you want to have multiple operations added to the Undo stack, you can force it by calling app.redraw() in your script. If you are looping over an array, adding app.redraw() into the loop will give you one undo operation for each iteration.

 

- Mark

wckdtall
wckdtallAuthor
Inspiring
July 19, 2023

Thanks both! I'm actually wanting to wrap several actions into one history state. My script creates a layer, names it, makes a text disclaimer, outlines it, sets visibility. It consistently only records 2 undo states, but in PS and ID an entire loop with hundreds of changes can be contained within these so they don't record. I do use redraw quite a bit, but mostly because Illustrator needs it to update scripts that run too fast. On that note, it may be in part why such this functionality doesn't exist.

CarlosCanto
Community Expert
Community Expert
July 18, 2023

There are no suspendHistory or undoModes in Illustrator.

 

I tried changing the undoDepth since it seems the History steps are related to the number of undos. But it seems the minimum number of undos is 5. Are you trying to prevent a large number of undos in memory?

 

app.preferences.setIntegerPreference ("maximumUndoDepth", 5);