# How to automatically rename empties created with hook operator

I need to rename each new empties I've made. Can you help me?

import bpy, bmesh

#select vertex

bpy.ops.object.mode_set(mode = 'OBJECT')
obj = bpy.context.active_object
bpy.ops.object.mode_set(mode = 'EDIT')
bpy.ops.mesh.select_mode(type="VERT")
bpy.ops.mesh.select_all(action = 'DESELECT')
bpy.ops.object.mode_set(mode = 'OBJECT')
for vert in range(len(obj.data.vertices)):
obj.data.vertices[vert].select = True
bpy.ops.object.mode_set(mode = 'EDIT')

• – Markus von Broady Apr 12 at 8:46
• – batFINGER Apr 12 at 11:12
• & with modifiers blender.stackexchange.com/q/196746/15543 using operator to add empty. Recommend method of former, (adding via bpy.data.objects.new(...)) to avoid performance issues related to blender operators. – batFINGER Apr 12 at 11:24

The hook is the object of last modifier.

When a modifier is added it is going to be the last one on the modifiers stack. Since the operator has added both the modifier and the empty and assigned it to the object property of the modifier, then

new_mod = obj.modifiers[-1]
new_mod.object.name = "Foo"


The whole process of adding hooks can be achieved without using the operator as demonstrated here, or any operator had the empties not been added with one

How can I animate a vertex translation of a triangular mesh?

and the "opposite" ie parenting empties to verts so they follow verts

Blender python to hook vertex and empty

Have used foreach_set to deselect all edges and faces and each vert. Basically for a 3 vertex object

me.vertices.foreach_set("select", [True, False, False])


is equivalent to

me.vertices[0].select = True
me.vertices[1].select = False
me.vertices[2].select = False


Test Script.

import bpy

obj = bpy.context.object
me = obj.data
# deselect all faces and edges
me.polygons.foreach_set("select", (False,) * len(me.polygons))
me.edges.foreach_set("select", (False,) * len(me.edges))
n = len(me.vertices)
for i in range(n):
bpy.ops.object.mode_set(mode='OBJECT')
me.vertices.foreach_set("select", [i == j for j in range(n)])
bpy.ops.object.mode_set(mode='EDIT')
obj.modifiers[-1].object.name = f"Hook_{i}"

bpy.ops.object.mode_set(mode = 'OBJECT')


just add this line as last line:

bpy.data.objects['Empty'].name = "Hook1"

• It just renames the cube, not the plain axes [![enter image description here][1]][1] [1]: i.stack.imgur.com/JWXmp.png – Michele Apr 12 at 8:52
• sorry, you are right...i will search for the right solution – Chris Apr 12 at 8:54
• i updated my answer – Chris Apr 12 at 8:57
• @batFINGER: i did indent it - it didn't work. It changed the cubes name, but not the empty name. And i have no idea why. i just tested it. – Chris Apr 12 at 11:43
• Yep my bad, forgot it was edit mode. Anyway recommend using API method to add and wire up the hooks and remove the need for edit mode altogether. See my last link under OP. Test for any preexisting objects named "Empty" first if using method above. – batFINGER Apr 12 at 11:47