Skip to main content
Inspiring
April 20, 2022
Answered

CEP panel - UndoGroup is not created

  • April 20, 2022
  • 1 reply
  • 670 views

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();

 

 
Now I moved to CEP panels where most calculations are done in my js or vue file. Functions in CEP contain loops which call the .jsx several times to add layers one by one. All the right layers, shapes and keyframes are added in the right order, all is fine there.
 
But I wish to put an Undo Group around all this. I have a hard time finding out how to achieve this. In the console log I see that beginUndoGroup, the adding of the layer(s) and the endUndoGroup are called in the right order. But File > Undo will only show me the individual actions.  
 
I now start the doubt that I set up my script the right way, maybe I should gather all the evalScripts and call the JSX just once? On the other hand, I think it defeats a lot of other advantages. Anyway, I am quite lost here, but I assume I'm not the first one facing this problem. 
 
I tried to simplyfy it here. Adding just one layer with undo group around it.

 

// 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;
}

 

 
Any pointer in the right direction is greatly appreciated!
 
 
This topic has been closed for replies.
Correct answer Mathias Moehl

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.

1 reply

Mathias Moehl
Community Expert
Mathias MoehlCommunity ExpertCorrect answer
Community Expert
April 21, 2022

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.

Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects
Inspiring
April 21, 2022

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. 

Mathias Moehl
Community Expert
Community Expert
April 21, 2022

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.

Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects