It looks like many of the operators dont work after bpy.ops.wm.open_mainfile.
I am trying to open a file from Blender via bpy.ops.wm.open_mainfile and then use the Make Instances Real operator to make all instances in that newly opened file real, but the operator does nothing. I also realised that many other operators dont work after bpy.ops.wm.open_mainfile.
Whats wrong with my code? This seems like a very simple task…
I can say that when a new file is opened everything in the current file (all of the instantiated data) will be lost. In this case the text editor will loose all of the text files. Also all of the operators or panels, that exist in the current active context.
However for Addons this is not the case since they can be registered at any given time (reload / enable / startup). So the right approach is to turn the script to a simple Addon.
Did you test this?
The code in my original post was acutally part of an addon, but still had the same problem. The weird thing is, that some operators like select_all work, but others like duplicates_make_real dont.
I managed to solve the problem in a different way:
I wrote a simple python script, that opens Blender and executes a “processor” script which does the bpy.ops.object.duplicates_make_real() among other things.
This is the call to open Blender and run the processor: subprocess.run("blender -b " + filename + " -P processor.py", cwd=dir_path)