Skip to main content
Inspiring
February 22, 2019
Answered

Odd suspendHistory behavioud

  • February 22, 2019
  • 1 reply
  • 754 views

I stumbled upon some strange behaviour of suspendHistory.

In JSX, there are, basically, 2 ways of writing code that I know.

1. When you write public named functions that are later called through the CSInterface bridge.

Like:

myFunc = function() {

  //do something
}

2. To make the code a bit more clean I started making kind-of-classes to have common pieces together. For example, a class for all layer-related scripts, or all channel-related scripts.

Like:

function LayersTools() {

   this.publicMethod = function() {
   }

   function privateMethod() { ... }

}

Now as it turned out, calling

app.activeDocument.suspendHistory("Test", "myFunc()")

works fine

but

app.activeDocument.suspendHistory("Test", "new LayersTools().publicMethod()")

doesn't suspend internal code of `publicMethod()`

So if, for example, my publicMethod() creates a new layer, this entry will not be suspended.

And if I re-write this as

LayerTools_publicMethod() { //create new layer }

and call it

app.activeDocument.suspendHistory("Test", "LayerTools_publicMethod()")

it will work just fine, all entries will be with suspended history

Does anybody has any insight on this?

This topic has been closed for replies.
Correct answer AverinAAA

I love mornings. They always bring clarity and solutions, to everything =)
When writing suspendHistory I forgot to put script parameter into brackets and it wasn't a valid string. So it wasn't working

1 reply

AverinAAAAuthorCorrect answer
Inspiring
February 23, 2019

I love mornings. They always bring clarity and solutions, to everything =)
When writing suspendHistory I forgot to put script parameter into brackets and it wasn't a valid string. So it wasn't working

Kukurykus
Legend
February 23, 2019

What parameter in which brackets? Post it

AverinAAAAuthor
Inspiring
February 23, 2019

Signature is app.activeDocument.suspendHistory(string, string)

First parameter is the new history entry name, second parameter is a script to run, in string.

I have this helper method:

suspend = function (name, action) {

    if (!action || action == "undefined") {

        log(">>> ERROR <<< suspending undefined script for " + name)

        return

    }

    app.activeDocument.suspendHistory(

        name,

        "try { " +

        action +

        ' } catch(e) { log(e + " while running ' +

        action +

        ' " ) }'

    );

}

Part about action being undefined I added today =) Because I was calling my extension
runCSScript('suspend("New History Name", myClass.doMyStuff())')

second argument was interpreted as undefined and nothing was running correctly.

Correct way, of course,was

runCSScript('suspend("New History Name", "myClass.doMyStuff()")')