1
$\begingroup$

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].

$\endgroup$
2
$\begingroup$

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))
| improve this answer | |
$\endgroup$
  • $\begingroup$ you are a star. I the meantime four a similar thing with obj.matrix_world.translation.y. But your code is perfect, thank you. $\endgroup$ – Andy Andy Jun 28 at 20:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.