I'm on Blender 3.6 where the old way to override context is deprecated. I know that some
bpy.ops commands need to be run in a certain context. I'm fairly certain that I need to be in VIEW_3D context to run
bpy.ops.view3d.view_axis(type='TOP', align_active=True) which is equivalent to Shift+NumPad-7 (View > Align View > Align View to Active > Top), but it does not work and is telling me failed, context is incorrect. If the context is not VIEW_3D, I wonder what it is then?
import bpy area_type = 'VIEW_3D' areas = [area for area in bpy.context.window.screen.areas if area.type == area_type] with bpy.context.temp_override( window=bpy.context.window, area=areas, regions=[region for region in areas.regions if region.type == 'WINDOW'], screen=bpy.context.window.screen ): bpy.ops.view3d.view_axis(type='TOP', align_active=True)