1
$\begingroup$

Calling context.area.ui_type = 'IMAGE_EDITOR' succeeds before redraw.

After redrawing using bpy.ops.wm.redraw_timer(type='DRAW_WIN_SWAP', iterations=1) it fails, with the error:

AttributeError: 'NoneType' object has no attribute 'ui_type'

How can I restore the context so that area is not NoneType ?

$\endgroup$

1 Answer 1

2
$\begingroup$

The solution was to Override the Context:

Blender 3.2+

import bpy
from bpy import context

# Before calling redraw, create the override dict
override = context.copy()

# After redraw, set the area on the override instead of the context object
override['area'].ui_type = 'IMAGE_EDITOR'

# Pass the overrides as a dictionary to the context manager 
with context.temp_override(**override):
    bpy.ops.image.save_as(filepath = my_filepath)

Blender 2.8+

import bpy
from bpy import context

# Before calling redraw, create the override dict
override = context.copy()

# After redraw, set the area on the override instead of the context object
override['area'].ui_type = 'IMAGE_EDITOR'

# Any bpy.ops.* calls must pass the override as the 1st argument eg:
bpy.ops.image.save_as(override, filepath = my_filepath)
$\endgroup$

You must log in to answer this question.

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