Activity › Forums › Adobe After Effects Expressions › Perform an Undo action using script?
-
Perform an Undo action using script?
Posted by Nguyễn Quang on September 13, 2012 at 4:14 pmHow can I use script to simulate an Undo/Redo action in After Effects?
Marcus Rivers replied 3 years, 7 months ago 4 Members · 7 Replies -
7 Replies
-
Dan Ebberts
September 13, 2012 at 4:43 pmIt’s tricky. If you create a new solid layer, for example, you can undo that action from a script with this pair of undocumented commands:
app.executeCommand(app.findMenuCommandId(“Undo New Solid”));
The catch is that you have to know the exact name of the undo item, which of course changes based on what you did last. If you want to undo something that the script did, you probably have a better chance, because the script can create an undo group, which you have to name, so you would know the name in that case. I haven’t tried it, and I’m not particularly confident that it will do what you need.
Dan
-
Nguyễn Quang
September 13, 2012 at 5:07 pmOh my god! I had been looking everywhere for this command.
Now my problem is solved! You are my life saver! Thank you very much! 😀 -
Arne Münch
August 7, 2016 at 12:59 pmI try to include an Undo Button in my Script but it doesn´t seem to work properly with your code. I tried:
myPanel.grp.group1.undoButton.onClick = function(){
undoFinder = app.findMenuCommandId("Undo: Shape"); //Shape is the name of my undo group
app.executeCommand(undoFinder);
var i = 0; //Variable To prevent from infinity Loop
while (undoFinder != 0 && i<10){
undoFinder = app.findMenuCommandId("Undo: Shape");
app.executeCommand(undoFinder);
i++;
}
}
I try to undo all actions which occured after "Shape" including "Shape", but the variable "undoFinder" behaves strange. Any ideas how to get that? -
Dan Ebberts
August 7, 2016 at 5:31 pmI think in both cases after you use app.findMenuCommandId(“Undo: Shape”), you need to check for zero before you use app.executeCommand(undoFinder).
-
Dan Ebberts
August 7, 2016 at 5:36 pmIgnore that last post. I just tried it and executing a command with an ID of zero doesn’t cause an error, so I guess you don’t need to check for it.
Dan
-
Arne Münch
August 8, 2016 at 10:22 amThank you Dan.
Yes I know, checking that ID doesn´t cause an error, but the code does´t work, the behavior of that ID is not understandable for me.Alternative idea:
I there a command for finding an Undo Action in the protocol and and than execute that instead? -
Marcus Rivers
November 9, 2022 at 11:13 pmIn case anyone else is viewing this question, the above suggestion to search for the Undo term does work, if the term is entered correctly; in this case, it shouldn’t contain a colon.
If the action was called “Shape”, then the undo term would be “Undo Shape” (not “Undo: Shape”).
Reply to this Discussion! Login or Sign Up