I am trying to make loopcuts on an object in a Python script running Blender 2.77a in the background with the "-b" commandline option. If I don't override the context I get this error:
bpy.ops.mesh.loopcut.poll() expected a view3d region & editmesh
There is an answer for this here on StackExchange:
...and the loopcut override works when Blender is in the foreground. But when using the technique in the background, this error comes up:
wmSubWindowScissorSet 0: doesn't exist
...and Blender crashes. Online searches don't help on this, I could find no solution. That leads me to the question - can this be done? How can the context be overrriden so that it will work in the background?
My context override is done like so:
def context_override(): for window in bpy.context.window_manager.windows: screen = window.screen for area in screen.areas: if area.type == "VIEW_3D": for region in area.regions: if region.type == "WINDOW": ctx = bpy.context.copy() ctx["window"] = window ctx["screen"] = screen ctx["area"] = area ctx["region"] = region ctx["scene"] = bpy.context.scene return ctx