Quickly moving the 3D viewport to the center of the scene in Blender

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:

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:

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:

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).

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:

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.

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comment
Newest
Oldest Most Voted
Inline Feedbacks
View all comments