Hello dear blender community,

I am trying to automate a few tasks in Blender, and trigger their execution from the command line like this: blender %file% --python myScript.py. My script is calling an installed Addon developed by someone else. This addon is calling at several points in the code bpy.context.area to set the context for some bpy.ops. operators. This is were my struggles start. As I am calling blender from the CMD without the --background argument, I (possibly falsely) assumed that the context and ops are unaffected, sadly though I cannot force blender to set a bpy.context.area. I tried to set a context using this:

for window in bpy.context.window_manager.windows:
    screen = window.screen
    for area in screen.areas:
        if area.type == 'VIEW_3D':
            override = {'window': window, 'screen': screen, 'area': area}

but it fails on setting an area, and bpy.context.area remained a NoneType. Is there a way I can call blender from CMD, let it first draw a GUI and only call my script headlessly once the bpy.context.area is no longer a NoneType? I tried naively a time.sleep statement, and tried different ways of setting a context to one of the areas from bpy.data.screens['xx'].areas[0], but failed so far. Does anyone have a CLI argument or a snippet I can add to my code to create a bpy.context.area?

I am running Windows and Blender 2.93.1.

Many thanks!!


1 Answer 1


you can override context in blender is your script also calling context dependent if so you can override it with something like this .

import bpy
override_context = bpy.context.copy()
area = [area for area in bpy.context.screen.areas if area.type == "VIEW_3D"][0]
override_context['window'] = bpy.context.window
override_context['screen'] = bpy.context.screen
override_context['area'] = area
override_context['region'] = area.regions[-1]
override_context['scene'] = bpy.context.scene
override_context['space_data'] = area.spaces.active

also readup more here https://b3d.interplanety.org/en/context-override/

  • $\begingroup$ Are you sure this is the answer to the question above? I don't think it helps to acquire bpy.context.area when a python script was running in the background. $\endgroup$
    – dalbom
    Commented Sep 26, 2021 at 7:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .