Featured post

new redirect for blender.org bpy docs.

http://www.blender.org/api/blender_python_api_current/ As of 10/11 november 2015 we can now link to the current api docs and not be worr...

May 14, 2011

Blender 2.5 Python Moving Object Origin

the tooltip for changing the origin (with object selected in object mode) = shift+ctrl+alt+c. says: bpy.ops.object.origin_set(...)

http://www.blender.org/documentation...ps.object.html
a pretty painless procedure, but maybe a little obfuscated.
- copy the coordinates of your current 3d cursor
- set the 3d cursor to your desired world coordinates
- set the object origin to the 3d cursor
- update
- set the 3d cursor back to it's initial position
- update (if needed )

that in python looks like
import bpy
# store the location of current 3d cursor
saved_location = bpy.context.scene.cursor_location.copy()  # returns a copy of the vector

# give 3dcursor new coordinates
bpy.context.scene.cursor_location = (1.0,0.0,0.0)

# set the origin on the current object to the 3dcursor location
bpy.ops.object.origin_set(type='ORIGIN_CURSOR')

# set 3dcursor location back to the stored location
bpy.context.scene.cursor_location = saved_location