I used to export layers by deleteing the ones I didn't want, then exporting as an illustrator file, then undoing all the layer deletions.
Recently I had to switch up so that I call another plugin which inserts information into the file I'm working on. Then that plugin sends control back to the original to do all the ai file exporting I mentioned above.
Somehow after I get controll back I cannot undo the layer deletions. Does it have something to do with the "nested plugins" notes in the contexts sections of the undo documentation.
I have to confess I don't fully understand these "contexts". Also if there's another way to export a layer of a file other than deleting all the other ones, I'd love to hear it.
A little more info.
The plugin which saves the AI files can be interupted by the other plug-in or not depending on user settings.
I checked the "undo context" in both cases.
When the plugin is NOT interupted, it DOES allow undochanges() and it's running in "silent" mode.
When the plugin IS interupted, it does NOT allow undochanges() and it seems to be running in normal mode. Also if I set it to "silent" it does not fix the issue.
I found an obvious work around for my particular plugin (simply saving a copy of the document, THEN deleting undesired layers, then resaving, duh) but I still don't understand why the UNDO stops working after I get control back to my plugin.