Blocking the UV elements from moving beyond the UV area boundaries

In most cases, UV elements (vertices, edges, faces, islands) can be freely moved anywhere in the UV Edit area. However, sometimes it is undesirable to move the UV beyond the boundaries of the base UV borders, for example, to ensure that the UV does not “move away” when baking it into atlases.

Blender provides a simple and effective method that blocks the movement of UV elements beyond the base boundaries.

To enable it, select the “UV” item in the main menu of the UV Edit area and check the “Constrain to Image Bounds” checkbox.

After that, when moving the UV elements, they will stop at the base boundary and not move beyond it.

To restore free movement of the UV, uncheck the checkbox.

This mode can also be enabled/disabled using the Blender Python API.

First, we need to get a pointer to the UV Edit area.

Since the UV Edit area belongs to the general “IMAGE_EDITOR” type, to be sure to get a pointer to the UV editor, we additionally check the “ui_type” subtype, which must be equal to “UI”.

Having received a pointer to the area, we can use it to get a pointer to the required “lock_bounds” property. Check its current state:

The value is False, which means that the option is not enabled (the checkbox is not checked).

Let’s enable it (check the checkbox) by assigning a True value to the property.

To disable blocking mode (uncheck the checkbox), assign the “lock_bounds” property the False value.

 

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comment
Newest
Oldest Most Voted
Inline Feedbacks
View all comments