Moving the origin position of the Rubik's Cube

I would like to move the position of a Rubik’s Cube I created to the origin in a scene using python. I do not know how to write a script for this. Please help.

Welcome to BA :slight_smile:

What you’re looking for is here:

To preserve against link-rot, here’s the relevant script:


context = bpy.context
ob = context.edit_object
me = ob.data
bm = bmesh.from_edit_mesh(me)

f = bm.faces.active
if f:
    o = f.calc_center_median()
    bmesh.ops.translate(bm,
           verts = bm.verts,
           vec = -o,
           )
    bmesh.update_edit_mesh(me)
    me.update()           
    # move the object globally to reflect
    mw = ob.matrix_world
    t = mw @ o - mw @ Vector()
    mw.translation += t