Controlling 3D Viewport with the Blender Python API

With the Blender Python API we can manage not only scene objects, but also the view from the 3D viewport area, The viewport has a matrix with which the viewport can be moved to the desired position.

To manage the viewport, we first need to get its area.

Let’s loop through all open areas until we find the viewport:

We can interact with the viewport matrix through its 3d region. We can access the 3d region of the viewport, having its area, as follows:

We can get the viewport matrix from the region through its view_matrix property

To save the viewport position and view, we need to save this matrix:

Through this view_matrix property, we can set a new position for the viewport by assigning it a matrix with the desired values.

For example, to set a 3D viewport to the front view, we need to assign the following matrix to the view_matrix property:

And in order to return the viewport to its original position, assign the previously saved value to the view_matrix property.

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comment
Inline Feedbacks
View all comments