Undo group mismatch working with render queue and AME in ExtendScritp
Hi everyone.
I have a couple of functions to send comps to the After Effects render queue and to AME:
const sendToAME = (options: KT_RenderOptions) => {
const RQItems: RenderQueueItem[] = addToQueue(options);
if (app.project.renderQueue.canQueueInAME) {
app.project.renderQueue.queueInAME(false);
}
for (let i = 0; i < RQItems.length; i++) {
const rqItem = RQItems[i];
rqItem.remove();
}
return RQItems;
};
const addToQueue = (options: KT_RenderOptions): RenderQueueItem[] => {
const RQItems: RenderQueueItem[] = [];
const compsArray = options.comps instanceof Array ? (options.comps as CompItem[]) : [options.comps as CompItem];
const templateName = options.template || this.DEFAULTE_TEMPLATE;
for (let i = 0; i < compsArray.length; i++) {
const comp = compsArray[i];
if (!is.comp(comp)) continue;
const rqItem = app.project.renderQueue.items.add(comp);
const om = rqItem.outputModule(1);
om.applyTemplate(templateName);
let outputFilePath = IO.path.join(options.path, `${comp.name}`);
outputFilePath = IO.path.sanitize(outputFilePath);
om.file = new File(outputFilePath);
RQItems.push(rqItem);
}
return RQItems;
};
At first, it worked perfectly, but suddenly I started getting the familiar "Undo group mismatch, will attempt to fix" error.
I've been looking for information and found that After Effects creates its own internal undo groups ("undoables") when working with the render queue tha may cause errors.
When I run the vscode debugger with breakpoints step by step, it never fails so I've tried wrapping the functions with empty undo groups and adding only `app.endUndoGroup` at the end of each iteration, but the error persists.
Does anyone with experience know how to fix this correctly?
