To switch to the view from the active camera we can execute the following command:
1 |
bpy.ops.view3d.view_camera() |
This operator works in the toggle mode, so the next executing of the same command returns the view to the previous state.
We can switch to the camera view without using operators from bpy.ops.
The following code switch to the camera view for the first “3D View” window:
1 2 3 |
region = next(iter([area.spaces[0].region_3d for area in bpy.context.screen.areas if area.type == 'VIEW_3D']), None) if region: region.view_perspective = 'CAMERA' |
And for all windows:
1 2 3 |
for area in bpy.context.screen.areas: if area.type == 'VIEW_3D': area.spaces[0].region_3d.view_perspective = 'CAMERA' |
If we need to switch to the camera view for the current window (for the certain context):
1 |
context.space_data.region_3d.view_perspective = 'CAMERA' |
Excellent post. I was looking how to do this and you got me over the hump.
Thanks.