Copy link to clipboard
Copied
Dear all,
Long time lurker here, now I got stuck and can not find a solution. I hope someone can point me in the right direction.
Before I went into CEP panels, I could easily create an undo group.
// in jsx
app.beginUndoGroup("My Undo Group");
//adding layers here
app.endUndoGroup();
// in CEP
addLayers(){
let myLayer = evalScript(`addLayer()`);
return true;
},
mainFunction(){
var beginResult = evalScript('beginUndo();');
if (beginResult){
var layerResult = _this.addLayers();
if (layerResult){
var endResult = evalScript('endUndo();');
}
}
}
//in JSX
function beginUndo(){
app.beginUndoGroup("My Undo");
console.log('beginUndo() called');
return true;
}
function endUndo(){
app.endUndoGroup();
console.log('endUndo() called');
return true;
}
function addLayer(){
var comp = app.project.activeItem;
var layer = comp.layers.addShape();
console.log('addLayer() called');
return true;
}
If I remember correctly, after a JSX script has been executed, any still open undo groups are closed automatically. Hence, your only option (as you already suggested) is to refactor your code such that everything that should be undoable in a single step is also executed in a single jsx script.
Copy link to clipboard
Copied
If I remember correctly, after a JSX script has been executed, any still open undo groups are closed automatically. Hence, your only option (as you already suggested) is to refactor your code such that everything that should be undoable in a single step is also executed in a single jsx script.
Copy link to clipboard
Copied
Thank you Mathias, that sounds exactly like how it seems to work and it suddenly makes a lot of sense that it works like that. I'm already in the process of refactoring, which is not even that big deal, I just collect all the code in an object and iterate through it. Good thing is that it give me the opportunity to implement a progressbar since now I know exaclty what will be executed. And definitely good to know it's the right way. Many thanks.
Copy link to clipboard
Copied
Yes, I also think that it makes sense. If a script could open an undo group without closing it, the user could perform actions (or undos) while the group is still open, which could create chaos.
Copy link to clipboard
Copied
It works now. Not sure if this solution adds something substantial to the anwser because it apparently has more to do with beginner level scripting then CEP or After Effects.
At every position in CEP where I called JXS to exececute a function I replaced that line with a function which adds the JSX function with its JSONString in an array. First index gets beginUndoGroup(), last one gets endUndoGroup(). A callback in my main function executes every record in the array after the calucaltions are done. Instead of hundreds of actions that the scripts performed, a single Undo appears in the menu.