Undo operator changes after operator is finished

I am trying to make .fbx export addon that exports groups as merged objects. So I make a new scene, instantiate groups objects, join them to object named by group name and export them. I also set object.name explicitly after creating new objects so they have right name when exported, but this can give wrong names to some of old objects. Is there a way around this, for example I can use undo to get old names, but can I call undo inside operator?

I think this will be quite tricky. You can try to use the undo operator, but I doubt you’ll have much success.

Maybe you should go another route. Run a python script with blender my_file.blend --background --python myscript.py

That would not be an operator accessible from within Blender, but if this is part of a regular “build” process any way, you may just as well run it on the command line. The script wouldn’t save the blend file, so everything is as before.

Because of the way operators work and interact, it is really difficult to isolate your own script/operator from the rest of the blender instance, so sometimes it’s best to let the script run in a “sandbox” were the resulting blender data is just discarded…

Thanks for the idea. I’ll try that.

I found a bit hacky way the way to do it with undo inside operator:

# this reverts the changes