Copy link to clipboard
Copied
Hey everyone,
I have a script that imports an .aep file into the active composition. The script works, but when I try to undo, After Effects throws this warning:
Undo group mismatch, will attempt to fix.
It happens whenever I use app.executeCommand or other app. methods inside app.beginUndoGroup and app.endUndoGroup.
Code Snippet below;
export const ImportPrecomps = (PrecompName: string, Alpha: number, Theme: number) => {
try {
const comp = getActiveComp();
const myBin = getOrCreateBin("TestBin");
app.beginUndoGroup("Import Precomps");
let precomp = findPrecompInBin(PrecompName, myBin);
if (!precomp) {
const file = new File("/path/to/my.aep");
const importOptions = new ImportOptions(file);
app.project.importFile(importOptions);
// Find the imported precomp
precomp = findPrecompInBin(PrecompName, myBin);
if (precomp) precomp.parentFolder = myBin;
}
if (precomp) {
const newLayer = comp.layers.add(precomp);
newLayer.property("ADBE Layer Overrides").property(1).setValue(Alpha);
newLayer.property("ADBE Layer Overrides").property(2).setValue(Theme);
} else {
alert("Precomp not found: " + PrecompName);
}
} catch (e) {
alert("Error importing precomp: " + e);
} finally {
app.endUndoGroup();
}
};
The script works fine, but undoing throws the “undo group mismatch” warning. I suspect it might be due to app.executeCommand or the import operation affecting the undo stack.
Has anyone faced this issue before? Any suggestions on handling undo groups properly in this scenario?
Thanks in advance!
I tried this with multiple versions of AE. 2022, 2023, 2025 and beta. but no luck.
Copy link to clipboard
Copied
Undo group breaks when you are importing the file
Copy link to clipboard
Copied
Have you tried wrapping your beginUndoGroup() and endUndoGroup() around the entire try/catch/finally structure instead of inside try and finally? It seems like that would be safer.
Copy link to clipboard
Copied
Hey Dan, thanks for the reply.
I tried wrapping beginUndoGroup() and endUndoGroup() around the entire try/catch/finally structure, but it still throws the undo group mismatch error.
From Alex White's comment, I understand that importing a file breaks the undo group.
I tried a different approach by moving beginUndoGroup() after app.project.importFile(), which seems to fix the error for now. However, I can’t manually undo the file that was imported into the project panel.