Skip to main content
Inspiring
January 20, 2022
Question

UndoGroup in ExtendScript works, in CEP not. Why and how?

  • January 20, 2022
  • 1 reply
  • 600 views


Hello all,
I try to add an UndoGroup in my CEP panel, but it does not get added to the Undo menu.
When making a UI Panel I would use:

 

app.beginUndoGroup("Undo the Hello text");
var comp = app.project.activeItem;
var myTextLayer = comp.layers.addText("Hello");
app.endUndoGroup();

 

 

that would add a Text layer and the option Edit > Undo > Undo the Hello text.

 

With CEP I try it like this in 3 methods.

 

async BeginUndo(){
let result = await evalScript(`
(function() {
app.beginUndoGroup("Undo the Hello text");
}())
`)
console.log("BeginUndo");
}

async AddText(){
let result = await evalScript(`
(function() {
var comp = app.project.activeItem;
var myTextLayer = comp.layers.addText("Hello");
}())
`)
console.log("Adding a layer");
}

async EndUndo(){
let result = await evalScript(`
(function() {
app.endUndoGroup();
}())
`)
console.log("EndUndo");
}

function Start(){
this.BeginUndo();
this.AddText();
this.EndUndo();
}

Start();​

 

 

Results in the log:
-BeginUndo
-Adding a layer
-EndUndo

 

Result in the comp:
-a freshly added textlayer.

 

Besides this expected result, I wanted to see in the menu: Edit > Undo > Undo the Hello text
Instead, I only see Undo New textlayer. I assume methods are being called, but I guess I'm wrong and don't see what is going on.
Can someone point me in the right direction?
This topic has been closed for replies.

1 reply

Inspiring
January 21, 2022

To make it a bit more visual

// this adds my undo
let begin =  evalScript(`
app.beginUndoGroup(\"my undo\");
alert(\"begin\")
app.project.activeItem.layers.addShape();
alert(\"add\")
app.endUndoGroup();
alert(\"end\")
`);

 

//this does not add my undo

let begin = await evalScript(`
app.beginUndoGroup(\"my undo\");
alert(\"begin\")
`);

let between = await evalScript(`
app.project.activeItem.layers.addShape();
alert(\"add\")
`);

let end = await evalScript(`
app.endUndoGroup();
alert(\"end\")
`);

 The same code in one evalScript works, in three parts it doesn't. While (I assume) it all executes in the right order. 

Inspiring
January 21, 2022

I forgot to add, this is for After Effects.