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?
Asked
Active
Viewed 761 times
0
-
1What 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...? – Psyonic Nov 25 '20 at 07:49
1 Answers
3
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.
Psyonic
- 2,319
- 8
- 13
-
when swapping the last line an empty is added but I'd like it to be at the object origin. – Farid Abdelnour Nov 25 '20 at 13:38
-