Skip to main content
deltabox
Inspiring
December 16, 2021
Answered

Extendscript Undo Groups (app.beginUndoGroup) always throws error

  • December 16, 2021
  • 1 reply
  • 1774 views

I'm working on a script and I just finished creating a function that renders certain items and then import them into after effects.

I want to add 

app.beginUndoGroup('Render and import');

before the function and

app.endUndoGroup();

after the function, so I can undo all the actions within that function that affects the project.

Everything together looks like this

        button1.onClick = function () {
            app.beginUndoGroup('Render and import');
            getUnsupportedLayers();
            app.endUndoGroup();
           
            // app.executeCommand(app.findMenuCommandId('Undo')); // Edit Menu > Undo
            // app.executeCommand(16); // Edit Menu > Undo
        }

Here's a screenshot of all the actions performed in that function which can be found under Edit > History

This is basically the history for 1 imported item, since the final script will do this for multiple files I need an effective way to undo all actions for all items.

The errror I get with the from after effects when pressing CTRL+Z is:

"Undo group mismatch, will attempt to fix."

 

Otherwise everything works completely fine without the Undo groups involved.

My goal with this is to create a scriptui button that will undo all of those actions.

If any of you know a way to make this work or perhaps having the same issue then please let me know.

This topic has been closed for replies.
Correct answer manjunath MK

When you render ur undo history is cleared for some reason and you can't undo something which happend before render.

You may need to write script that can work like below.

 

Before render some actions are performed and then, trigger render from script > check if rendering is complete >after render is done > perform reveresed actions.

 

/// Plz refer that ae scripting guide for syntax

renderAndImport_button.onClick=function(){

myActions();

app.renderQueue.render();

if(app.renderQueue.stillRendering){

sleep(1 min)

}else{

myActionReversed();

}

 

}

 

// Plz refer that ae scripting guide for exact method and names

//See if this helps.

 

1 reply

manjunath MKCorrect answer
Inspiring
December 17, 2021

When you render ur undo history is cleared for some reason and you can't undo something which happend before render.

You may need to write script that can work like below.

 

Before render some actions are performed and then, trigger render from script > check if rendering is complete >after render is done > perform reveresed actions.

 

/// Plz refer that ae scripting guide for syntax

renderAndImport_button.onClick=function(){

myActions();

app.renderQueue.render();

if(app.renderQueue.stillRendering){

sleep(1 min)

}else{

myActionReversed();

}

 

}

 

// Plz refer that ae scripting guide for exact method and names

//See if this helps.

 

deltabox
deltaboxAuthor
Inspiring
December 17, 2021
quote

When you render ur undo history is cleared for some reason and you can't undo something which happend before render.

You may need to write script that can work like below.

 

Before render some actions are performed and then, trigger render from script > check if rendering is complete >after render is done > perform reveresed actions.

 

/// Plz refer that ae scripting guide for syntax

renderAndImport_button.onClick=function(){

myActions();

app.renderQueue.render();

if(app.renderQueue.stillRendering){

sleep(1 min)

}else{

myActionReversed();

}

 

}

 

// Plz refer that ae scripting guide for exact method and names

//See if this helps.

 


By @manjunath MK

"When you render ur undo history is cleared for some reason and you can't undo something which happend before render."

This was really useful information, thank you!
I made sure to create the Undo Group after rendering since the actions before rendering is just putting the comps into renderqueue.

I tried it out and it works flawlessly.

Tomas B. aka Tom10
Inspiring
December 17, 2021

Great to know that it works in this case - yet I faced undo group misbehaving when undoing complex script builds.

Workflow:
1. Project X opened.
2. Project X appended with new elements. Project remains opened.
3. If undo is made after the 2nd step - sometimes it undo's, sometimes not.

What I tried doing is to move undogroup into different locations of the script, considering that some events might be causing the issue. By now haven't found a proper workaround.