While trying to figure out how to manipulate bpy.context.screen.areas[5].spaces[0].region_3d.view_camera_zoom , I accidentally discovered that the Home key will make the camera bounds fill the viewport. If you try 'View All' from the spacebar menu it doesn't work exactly like the Home key (could not be bothered to hunt down why).
While not exactly useful, the examples at http://web.purplefrog.com/~thoth/blender/python-cookbook/screenshot-sequence.html might get you a little closer to the solution. Specifically
def viewMatrixFromCamera(cam):
"""
:param cam: the camera whose point of view is of interest
:return: the view matrix suitable for use in region_3d.view_matrix
"""
m2 = cam.rotation_euler.to_matrix()
m2.resize_4x4()
m3 = mathutils.Matrix.Translation(cam.location)
return (m3*m2).inverted()
def viewFrom(screen):
"""
:param screen:
:return: the "first" area in the specified screen that is a 3D view.
"""
for obj in screen.areas:
if (obj.type == 'VIEW_3D'):
return obj
return None
v3d = viewFrom(bpy.context.screen)
m1 = viewMatrixFromCamera(bpy.context.scene.camera)
print(m1)
v3d.spaces[0].region_3d.view_matrix = m1
Unfortunately this exact code is NOT what you need when you are actually looking through the camera. It only works to set the view when you are NOT looking through the camera.
Another problem is that while the code does move your focal point to the camera position, and gives you the correct orientation, it is highly unlikely to match the focal length of the camera. I have not been able to find any setting on the 3D view that allows you to adjust the focal length when you are not looking through the camera. When you "zoom in" you really just move the 3d view's focal point closer to the center point.