# Can loopcuts be made when Blender is in background with the “-b” option?

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:

How do I override context for bpy.ops.mesh.loopcut?

...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

• Related Might pay to check on window and screen to see that they aren't None in bg mode. – batFINGER Aug 9 '17 at 7:48
• Can you edit your post to add a minimal script which reproduces this issue (with the call to the mesh.loopcut) ? Thanks – Dominique Parisot Aug 31 '17 at 15:45

• Be careful, the context does exist in background mode, and operators are available. But as Bastien in the video you linked explains it is discouraged to use operators in background mode, as many (but not all) of them require a screen, an area or the like to work properly. You can test this in a command line. Enter blender -b --python-expr "import bpy;print(bpy.context)" - it will return something like <bpy_struct, Context at 0x7fa0408afc48>, which is a context object. – aliasguru Dec 10 '17 at 9:27