When working with large landscape scenes in Blender, sometimes we need to quickly return to the center from the current position of the 3D viewport. To avoid having to “scroll the mouse”, we can write a simple script for this.
The viewport position in Blender can be managed using the Blender Python API.
First, get a pointer to the 3D viewport’s area:
|
1 2 3 |
area = next(area for area in bpy.context.screen.areas if area.type == 'VIEW_3D') # <bpy_struct, Area at 0x000002ADB514C2E0> |
Areas in Blender are divided into regions to separate the UI from the actual part of the viewport where the scene is displayed.
Get a pointer to the desired region:
|
1 2 3 |
region = area.spaces[0].region_3d # <bpy_struct, RegionView3D at 0x000002ADB84E9420> |
Using this pointer, we can access the viewport’s parameters, in particular, its location in the scene.
The current position of the 3D viewport is determined by the “view_location” property.
We get its current position:
|
1 2 3 |
print(region.view_location) # <Vector (15.2686, -8.7005, 11.5624)> |
And also set the position we need by simply assigning the desired value. To move the viewport to the scene origin, we need to set the view_location property to (0.0, 0.0, 0.0).
|
1 |
region.view_location = (0.0, 0.0, 0.0) |
The viewport will immediately move so it faces the center of the scene.
When working at a distant point in the scene, we can greatly zoom in or out on the viewport. Therefore, it is useful to additionally adjust the viewport’s distance from the center after moving it.
This can be done using the region’s “view_distance” property.
Let’s assign a convenient value to this property:
|
1 |
region.view_distance = 10 |
Now, when the script runs, the viewport not only moves toward the center of the scene, but also moves away from or toward the desired distance from the center.

.blend file on Patreon