I would like to use the Python API to:
- set the parent of a set of objects to an empty object
- then set the location of the empty object to the midpoint of the bounding box of all objects
but not move all the objects
Step 1 works ok - but I am stuck on the second.
I start with this situation:
and after grouping things look like this:
with the origin of
e (the empty object) set at [0, 0, 0]
Now if I try to re-center the empty doing this:
def recenter(obj, point): try: obj.data.transform(mathutils.Matrix.Translation(-point)) except: print('obj has no data') print('translation', obj.matrix_world.translation) print('location', obj.matrix_world.translation) obj.matrix_world.translation += mathutils.Vector(point) print('translation', obj.matrix_world.translation) print('location', obj.matrix_world.translation) return(obj) tidy_names(locals()) recenter(e, [1.5, 1.5, 0.5])
I end up with:
Is there a shorthand way of doing this? I suspect I could recurse through all the children and reset, but that seems quite insane...