A simple script for transferring the origin of all selected objects to the origin of the active object.
1 2 3 4 5 6 |
import bpy cursor_backup = bpy.context.scene.cursor.location.copy() bpy.context.scene.cursor.location = bpy.context.object.location bpy.ops.object.origin_set(type='ORIGIN_CURSOR', center='MEDIAN') bpy.context.scene.cursor.location = cursor_backup |
At first, we save the current position of the cursor (because it will be used when transferring origins) to return the cursor to its current position after the script is executed.
Then we move the cursor to the origin of the active object.
With the “object.origin_set” operator, the origin of all selected objects is transferred to the cursor position.
Then the cursor returns to its original position.