Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Perform an Undo action using script?

  • Dan Ebberts

    September 13, 2012 at 4:43 pm

    It’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 pm

    Oh 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 pm

    I 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 pm

    I 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 pm

    Ignore 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 am

    Thank 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 pm

    In 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”).

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy