Overriding the selected objects list for the transform.translate operator

To execute an operator from a context that was not intended for it correctly, it is necessary to override the context for it using bpy.context.temp_override.() selected objects. However, using temp_override, we can override not only the context of the operator call, but also, for example, the stack of selected objects.

A list of all selected objects is stored in the bpy.context.selected_objects.

If we call the transform.translate() operator

all selected objects will move along the global X-axis.

We can use the same transform.translate() operator to move the objects we need, rather than the selected ones. To do this, before calling the operator, let’s temporarily override the list of selected objects.

Define a list with required objects:

And use the temp_override() function to override the list of selected objects, specifying the list we created.

Now we can call the transform.translate() operator again

As a result of its execution, not the selected objects will be moved, but only those that we specified in our list.

The full code:

0 0 votes
Article Rating
Notify of

0 Comment
Inline Feedbacks
View all comments