I had a script which included bpy.context
. Once I'd built the script up with various other functions, it was no longer working properly.
Using advice from here: Problem with bpy.context.selected_objects I changed various lines to use bpy.context.scene.objects if o.select_get()
instead of bpy.context.selected_objects
.
That worked nicely when I substituted into several of my def functions. Unfortunately in one function I'm relying on a built-in module (not sure if that is the correct term):
from bl_operators.uvcalc_smart_project import main as uv_smart_project
uv_smart_project(bpy.context, .02, 30, 0.03, True, True)
That one no longer works either, but as it is a built-in module I can't easily go in and update the module to use o.select_get()
. I get the error:
ob for ob in context.selected_editable_objects
AttributeError: 'Context' object has no attribute 'selected_editable_objects'
If, after the main script fails, I run the two problematic lines in a separate text block, then it runs fine.
Edit:
I have used context = bpy.context throughout, as that seems to be a recurring comment around here. Also called the problematic script via a different text block, but no difference. Finally tried an override like this:
for window in context.window_manager.windows:
screen = window.screen
for area in screen.areas:
if area.type == 'VIEW_3D':
override = {'window': window, 'screen': screen, 'area': area}
uv_smart_project(override, .02, 30, 0.03, True, True)
But that gives me 'dict' object has no attribute 'mode'
and I can't see how to add the mode to the override (if that is even a thing).
Is there another way to set the context correctly? Arbitrary selection/activation of an object in the 3D view, maybe?