Set 3D view to Camera

I’m looking for the correct code snipped to set the main 3D view to Camera view, said snippet to run from any python including the python console.

The offered python from the View/Camera tooltip is


but it produces an error:

Traceback (most recent call last):
File “<blender_console>”, line 1, in <module>
File “/Applications/blender-2.57b-OSX_10.5_x86_64/”, line 179, in call
ret = op_call(self.idname_py(), None, kw)
RuntimeError: Operator bpy.ops.view3d.viewnumpad.poll() expected a view3d region

It seems likely this is because there might be more than one view3d, but there has to be a way to control this for ops, right?

this displays all the visible window types

for i in bpy.context.screen.areas: print(i.type)

but that’s not going to help you :slight_smile: sorry dunno. interesting and i’m eager to find a solution for this because it’s block one of my scripts too.