Skip to main content
jonnyr39056025
Known Participant
July 19, 2017
Question

Function in script needs to generate NO history states at all

  • July 19, 2017
  • 2 replies
  • 1388 views

Is it possible using either javascript or scriptlistener way to prevent history states from being generated?

I'm writing a configurator 4 html extension and this part puts a guide on the canvas with the coordinate defined from a html text box - once the entry is updated the previous guide is removed and the new one added. I'm using scriptlistener code to create the guide as it seems to be the only way to force guides to toggle on to visible. Because this can be run an arbitrary number of times it would be far better if it didn't generate a history state every time it's updated. Is there a way to tweak the scriptlistener code to prevent history states? Simply reverting to a previous history state doesn't work as there may be other steps taken in between function calls, and removing the last index of document.guides doesn't work as other guides may be added in between also.

Currently I'm wrapping the update into a function and calling it through document.suspendHistory but it would be far better if it could be done 'silently' as far as the end user is concerned. I appreciate any thoughts, thanks

This topic has been closed for replies.

2 replies

darkie1973
Inspiring
August 14, 2017

Try this:

function main(){

//body of your script goes here//

}

app.activeDocument.suspendHistory ("put what you want the history to state here", "main()");

Hope this helps,

-Eric

JJMack
Community Expert
Community Expert
August 14, 2017

They want no history states that record one history like I appended before

JJMack
darkie1973
Inspiring
August 15, 2017

Oops,.... sorry!  Now that I've actually taken the time read his request thoroughly, I can see that!  Thanks for the correction and heads up JJMack!

-Eric

JJMack
Community Expert
Community Expert
July 20, 2017

No one history state will be created when you suspend creating history states for the script step with the name you code..

JJMack
Inspiring
August 12, 2017

have a look at the reply of David Barranca (DBarranca 11.11.2016 14:15).

He answered a similar question of Ian Barber.