I’m normally trying to avoid using bpy.ops, and I prefer to access and manipulate properties directly. However sometimes it’s unavoidable.
What would you say is the best way to override context that is not inside the screen.
My solution is to store the first area in the screen.
Replace the type of area to the desired area space.
Context override, and then restore back to the the intial area.
Here is an example for a function that switches temporarly to the NLA and moves the Nla tracks up and down, using the new api update for context override in Blender 3.2
def move_layer(dir, context): window = context.window screen = context.screen #Storing the type of the first area in the screen old_area = screen.areas.type area = screen.areas area.type = 'NLA_EDITOR' region = area.regions obj = context.object anim_data = obj.animation_data #deselect all tracks for track in anim_data.nla_tracks: track.select = False #select the correct track and use the operator anim_data.nla_tracks[obj.track_index].select = True with context.temp_override(window=window, area=area, region=region): bpy.ops.anim.channels_expand() bpy.ops.anim.channels_move(direction=dir)
This works all fine, and doesn’t really seem to glitch the screen. However it feels like a very hackish way to do it.
I was wondering if anyone knows a better solution? Can I access an area that is currently not inside context.screen? something like a ‘fake user’ area? or somehow to create it using bpy.types.Area?