Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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).
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
(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.
Copy link to clipboard
Copied
oh, nice. Thanks!
Copy link to clipboard
Copied
Does this mean that
app.executeCommand(16)
will execute the "undo" command?
Copy link to clipboard
Copied
Yes, that's what it does.
Dan
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Thank you!!:)
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now