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 =
bm = bmesh.from_edit_mesh(me)

f =
if f:
    o = f.calc_center_median()
           verts = bm.verts,
           vec = -o,
    # move the object globally to reflect
    mw = ob.matrix_world
    t = mw @ o - mw @ Vector()
    mw.translation += t