Extendscript Undo Groups (app.beginUndoGroup) always throws error

Community Beginner ,
Dec 16, 2021 Dec 16, 2021

Copy link to clipboard

Copied

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

FGfL9W9.png

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:

c33Xy5Y.png

"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.

TOPICS
Error or problem , Import and export , Scripting , User interface or workspaces

Views

99

Likes

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

Explorer , Dec 16, 2021 Dec 16, 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 syntaxrenderAndImport_button.onClick=function(){myActions();app.renderQueue.render();if(app.renderQueue.stillRendering){sleep...

Likes

Translate

Translate
Explorer ,
Dec 16, 2021 Dec 16, 2021

Copy link to clipboard

Copied

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.

 

Likes

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 Beginner ,
Dec 17, 2021 Dec 17, 2021

Copy link to clipboard

Copied

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.

Likes

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
Participant ,
Dec 17, 2021 Dec 17, 2021

Copy link to clipboard

Copied

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. 

Likes

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 ,
Dec 17, 2021 Dec 17, 2021

Copy link to clipboard

Copied

Try changing undoGroup name .

Else

Unless u don't have method to do something in scripting reference don't go for app.executeCommand().

 

Most of the tasks can be done using clean functions using built in methods or actions,  without using app.execute.

 

Post an example or attach an AE  file with issue.Let me check once.

Likes

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 Beginner ,
Dec 17, 2021 Dec 17, 2021

Copy link to clipboard

Copied

LATEST

I think using different undoGroup names as manjunath recommended can potentially help.

With this you can create a history of Undo states that you can reference in your code with if statements or so

Likes

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