Hi @dublove, yes in most cases it is possible. Just make sure you call your script using app.doScript and pass it UndoModes.ENTIRE_SCRIPT.
For example, this is my code on a question you posted previously:
function main() {
var doc = app.activeDocument;
var items = doc.selection;
// must update `items` with new item references
items = setItemStackingOrder(doc, items, sortByLeftTop);
// just for testing final order, print the names
for (var i = 0; i < items.length; i++) {
$.writeln(i + ': item ' + items[i].name);
}
};
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Set Stacking Order');
In fact, you you will see this on every script I have ever posted for you lol 🙂
- Mark
EDIT (for extra info): What we are doing is calling the `main` function using the app.doScript call. So any code you put in the `main` function will execute, even if it just calls another function. You don't have to use `main`—name it whatever you want. You can still use other functions as normal, so long as they are in scope (visible to the `main` function, for example).