I'm trying to import an OBJ file while rendering an animation, during the frame_change_pre
event. The purpose is to stream a sequence of meshes into Blender, one at a time just before each render. I've successfully done this in Blender 3.6 and earlier using the Legacy OBJ importer (bpy.ops.importer_scene.obj()
), but I'm running into problems with Blender 4.0 and the new OBJ importer (bpy.ops.wm.obj_import()
). I keep getting the error:
RuntimeError: Operator bpy.ops.wm.obj_import.poll() failed, context is incorrect
Looking at the Blender source code (source/blender/editors/io/io_obj.cc#L488), I've found that the poll function is the WM_operator_winactive
function. This function, as far as I can tell, simply checks for an active window, but correct me if I'm wrong.
I've tried using the bpy.context.temp_override()
function with no success. I'm not sure how to override the context. How can I override the context for this specific case? Or what workarounds might exist?