# Create empty through script using a cube as origin (0)

It is possible to create an empty through a script but will have a fixed distance to a selected cube? So lets say my cube is at [3,5,6] I want to be able to select it run the script an the generated empty to always be 2 units away on +Y from my selection. So in this case the empty will be at [3,7,6] in the world.

If for example a sphere is at [0, 11,0] generated empty using it as origin will be at [0,13,0].

See if this is what you want.

import bpy

#Get active(selected) object
act_obj = bpy.context.active_object

#Get active object location
act_loc = act_obj.location

#Add empty and set location based off active object
bpy.ops.object.empty_add(type='PLAIN_AXES', location=(act_loc.x, act_loc.y + 2, act_loc.z))

• you are a star. I the meantime four a similar thing with obj.matrix_world.translation.y. But your code is perfect, thank you. – Andy Andy Jun 28 at 20:52