• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

CEP panel - UndoGroup is not created

Explorer ,
Apr 20, 2022 Apr 20, 2022

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

 

 
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!
 
 
TOPICS
Error or problem , Scripting

Views

308

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Apr 21, 2022 Apr 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.

Votes

Translate

Translate
Community Expert ,
Apr 21, 2022 Apr 21, 2022

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.

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 21, 2022 Apr 21, 2022

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. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 21, 2022 Apr 21, 2022

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.

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 23, 2022 Apr 23, 2022

Copy link to clipboard

Copied

LATEST

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines