0
$\begingroup$

I have about 30 planes and would like to add an empty to each one of them, is there a way to do it using python instead of having to do it manually?

$\endgroup$
1
  • 1
    $\begingroup$ What do you mean by "add an empty to each one"? Do you mean create an empty then parent it to an object? Or make the empty the parent? Or something else...? $\endgroup$
    – Psyonic
    Nov 25, 2020 at 7:49

1 Answer 1

3
$\begingroup$

For Blender >2.80 this will work. Select all your objects and run this in the scripting panel.

import bpy

for object in bpy.context.selected_objects:
    obj_loc = object.location
    new_empty = bpy.data.objects.new( "empty", None )
    new_empty.location = obj_loc
    object.parent = new_empty # swap this line around to parent the other way
    object.matrix_world = object.matrix_parent_inverse
    bpy.context.scene.collection.objects.link( new_empty )
    

This will create new emptys at the object origins of all the selected objects, parent the object to the empty and remove any offset between the object and the empty.

$\endgroup$
2
  • $\begingroup$ when swapping the last line an empty is added but I'd like it to be at the object origin. $\endgroup$ Nov 25, 2020 at 13:38
  • $\begingroup$ I have updated the answer $\endgroup$
    – Psyonic
    Nov 26, 2020 at 10:21

Not the answer you're looking for? Browse other questions tagged .