Create a a segment with the given number of verts and hook and empty to every verts in the segment
<p>How can I create a segment with for example 30 verices and then connect an empty with an Hook parenting to every veritces in the segment, all this via Python in Blender 3d?</p>

<p>I'm going to say that this was frustrating but after trying several different approaches this is the one way that I got to work.</p>

<pre><code>import bpy
import bmesh

num_verts = 30

scn = bpy.context.scene
D = bpy.data.objects

verts = []
edges = []
for i in range(num_verts):
    verts += [(i, 0.0, 0.0)]
    if i &gt; 0:
        edges += [(i, i-1)]

mesh_data = bpy.data.meshes.new("hooked verts")
mesh_data.from_pydata(verts, edges, [])
mesh_data.update()
obj = D.new("Hooked line", mesh_data)
obj.select = True
scn.objects.link(obj)
scn.objects.active = obj

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

for i in range(len(obj.data.vertices)):
    bm = bmesh.from_edit_mesh(obj.data)
    bpy.ops.mesh.select_all(action='DESELECT')
    bm.verts.ensure_lookup_table()
    bm.verts[i].select = True
    bpy.ops.object.hook_add_newob()
    bpy.context.selected_objects[0].name = 'Hook'
    bm.free()

bpy.ops.object.mode_set(mode='OBJECT')
</code></pre>

<p>To assign a hook to a vertex, the object needs to be in edit mode with the desired vertex selected. It would seem that the add hook operators make a mess of the edit mesh data so that after the first hook modifier is created the mesh data is no longer valid. The solution - re-create the bmesh data and select a vertex after creating each hook.</p>

python blender segment vertices