Saving and restoring the 3D Viewport position

With the Blender Python API, we can work not only with scene objects, but also with the user interface (UI). For example, we can save and restore the position of the 3D Viewport in the scene.

Code author: Andrej

The position of the viewport in the Blender Python API is described by a number of parameters that can be stored in a list for ease of working with them.

We can get the current area of a 3D viewport using the following function:

The “save_viewport_position” function saves a copy of the current value for each of the previously listed viewport options.

The function returns a block of saved data.

To restore the saved viewport parameters, the “apply_viewport_position” function is used, in the parameter of which the previously saved data block is passed.

Way of use: save data about the current position of the viewport into a variable, change the viewport position if necessary, and call the restore function to return to the saved position of the viewport.

Full code:

 

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comment
Inline Feedbacks
View all comments