bpy.ops.view3d.view_selected() issue I try to import an obj file and make a rendered image, by a python script.
How to center the view to the mesh?

I've tried bpy.ops.view3d.view_selected() but i get this error:

Traceback (most recent call last):
  File "&lt;string&gt;", line 1, in &lt;module&gt;
  File "&lt;string&gt;", line 43, in &lt;module&gt;
  File "J:\Programmi\blender-2.75a-windows32\2.75\scripts\modules\bpy\ops.py", l
ine 189, in __call__
    ret = op_call(self.idname_py(), None, kw)
RuntimeError: Operator bpy.ops.action.view_selected.poll() failed, context is in
correct
If you don't have a reference to a specific window, you can iterate over all screen areas, and call the operator on all VIEW_3D area types.

for area in bpy.context.screen.areas:
    if area.type == 'VIEW_3D':
        ctx = bpy.context.copy()
        ctx['area'] = area
        ctx['region'] = area.regions[-1]
        bpy.ops.view3d.view_selected(ctx)            # points view
        # bpy.ops.view3d.camera_to_view_selected(ctx)   # points camera


I think the topic and resolutions to context is incorrect have been covered exhaustively . 

If you use camera_to_view_selected(ctx) you can break the loop early if you only have one camera to point, else it will point the camera at the same thing for every 3dview opened.