How can I move the user perspective in Blender with Python? I did some research, but I wasn't able, to find anything.

For clarification: I want to move the user camera in the 3D view. I want to achieve the same effect as the user pressing his middle mouse button and moving the mouse.

  • $\begingroup$ Are you asking how to zoom the camera when looking through it? $\endgroup$
    – iKlsR
    Nov 20, 2013 at 23:15
  • $\begingroup$ @iKlsR I want do the same, as if i would move around with my mouse. So, not only zooming... $\endgroup$
    – Fabian Parzefall
    Nov 21, 2013 at 13:29
  • $\begingroup$ You could try bpy.ops.view3d.move and rotate $\endgroup$
    – gandalf3
    Nov 21, 2013 at 19:27
  • $\begingroup$ @gandalf3 bpy.ops.view3d.move is not intended to be used from python. $\endgroup$
    – ideasman42
    Nov 21, 2013 at 23:26

1 Answer 1


You can use bpy.ops.view3d.view_pan() to do the same as Ctrl+Numpad #, e.g.:

for area in bpy.context.screen.areas:
    if area.type == 'VIEW_3D':
        override = {'area': area, 'region': area.regions[-1]}
        bpy.ops.view3d.view_pan(override, type='PANRIGHT')

The amount of the panning can't be controlled.

If you manipulate the view_matrix (or view_location etc.) directly, there's a lot more control. But you will have to calculate the proper matrices and vectors, and if something went wrong, you may end up with strange view or navigation reaction:

r3d = C.screen.areas[2].spaces[0].region_3d # region_3d of 3D View
r3d.view_matrix.col[3][1:4] # translation part of the view matrix

Have a look at the FPS Fly addon to see what can be done and how:

AFAIK viewport navigation is a bit weird after use, as the addon might manipulate the wrong property to fly around. The C-implementation will be different.


You must log in to answer this question.