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

Using undo groups

Explorer ,
Nov 05, 2015 Nov 05, 2015

Hi,

can I create undo groups and undo in code? Im not sure Im getting the idea of undo groups right. Can I "use" them ("undo") only in the AE or also script the "undo" action itself somehow?

AW

TOPICS
Scripting
2.8K
Translate
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 ,
Nov 05, 2015 Nov 05, 2015

The idea of undo groups is that if your script performs a lot of changes in the AE project, that the user can undo them in a single step.

Say your layer manipulates the in- and out-points of 10 different layers with the click of a single button. Then the user expects that this change can be undone be just doing a single undo and not by undoing 20 times (i.e. undoing the change of each in- and outpoint separately).

Undo is only for undoing changes of the AE project, not undoing other things in your script. Example: Im my script MaskTracker+, when you move some masks based on a track, you can only this movement for all the masks in one step. But if you load new tracking data in the script, this is nothing that can be undone by undo groups (this loading the tracking data is purely internal to the script and does not affect the AE project directly).

Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects
Translate
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
Contributor ,
Nov 05, 2015 Nov 05, 2015

We set something up like this (sorry, I don't know how to past code correctly):

previewDynamicContent : function(data) {

  app.beginUndoGroup("Execute Our Code");
     //our code

   app.endUndoGroup();
},
undoPreviewDynamicContent: function(){

  app.executeCommand(16);
}

and assigned the undoPreviewDynamicContent function to a button.

Translate
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
Advocate ,
Nov 05, 2015 Nov 05, 2015
(sorry, I don't know how to past code correctly):

For future reference you click "Use advanced editor" in the top right of the reply field, then choose the ">>" icon, "Syntax Highlighting", "javascript". What ever you have selected in your reply will  convert to JS code with syntax highlighting.

Screen Shot 2015-11-05 at 9.47.16 AM.png

Translate
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
Contributor ,
Nov 05, 2015 Nov 05, 2015

oh, nice. Thanks!

Translate
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 ,
Nov 08, 2015 Nov 08, 2015

Does this mean that

app.executeCommand(16)


will execute the "undo" command?

Translate
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 ,
Nov 08, 2015 Nov 08, 2015

Yes, that's what it does.

Dan

Translate
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 ,
Nov 09, 2015 Nov 09, 2015

But in general, Adobe does not guarantee, that these numbers stay the same for each release of After Effects.

Hence, if you want to be sure that it works on all machines you should do something like this:

var commandId = app.findMenuCommandId("Undo Execute Our Code");

app.executeCommand(commandId)


But note that this will only work with the English version of AE, unless you also search with app.findMenuCommandId for the label of the menu entry in all other possible languages.

Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects
Translate
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 ,
Nov 09, 2015 Nov 09, 2015

Thank you!!:)

Translate
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 ,
Nov 12, 2015 Nov 12, 2015

Ok, I have managed this to work. The only problem is that the function undoDynamicContent has to be called twice in order for the undo to work. Can somebody explain why is that? my code looks like this:

app.beginUndoGroup("Execute Code");

     //CODE

app.endUndoGroup();

undoDynamicContent();

undoDynamicContent();

function undoDynamicContent() {

    var commandId = app.findMenuCommandId("Undo Execute Code");

    app.executeCommand(commandId);

}

If I do not call the function in script, and it is done, it only takes one call in javascript console to work....

edit:

Sorry, in js console also the function has to be called twice in order to undo...

edit:

And what just came up i that undo action wont work after any render has been done:/ Is there any way around this??

Thanks for help!

A.

Translate
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
Contributor ,
Nov 12, 2015 Nov 12, 2015

I can't tell what's going on with just that code. If your undoDynamicContent function is self-executing, it is doing so before you have executed the code to be undone, from my understanding...?

Our undogroup is within a function that needs to be triggered, so that's the only scenario I'm familiar with.

Translate
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
Advocate ,
Nov 13, 2015 Nov 13, 2015
LATEST

tardigrade01, is correct. The code will execute upon script launch, so it is probably missing the undo call since it doesn't exist quite yet until the second call you make. Usually undo groups are just for the user to not have to undo lot's of processes that a script could make at any given point.

My question would be, if you are running a task that you will immediately undo, why run the task? I'm assuming you are trying to use the undo as some kind of cleanup method for what you are creating. If so then any temp comp, layer or physical item you create should have variable references, that you could simply call the .remove() method on after running your process. I'm guessing since I don't have all the details of what you are trying to accomplish though.

Translate
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