I am trying to hook my EMPTY to my lattice through the Blender API so when I move my EMPTY the lattice is deformed. As it is now when I run the code it shows that my EMPTY is connected to the center of the lattice which is not what I want.

If I were to do it through the 3D viewport I would add my lattice and add my EMPTY. Then I would first select the EMPTY followed by the lattice. Enter edit mode and select all vertices of the lattice. Then CTRL H and hook to selected object.

collection = bpy.context.collection
lattice = bpy.data.lattices.new("Lattice")
lattice_ob = bpy.data.objects.new("Lattice", lattice)
lattice_ob.scale = (224, 352, 224)
lattice_ob.location = (112, 176, 112)
lattice_ob.data.points_u = 5
lattice_ob.data.points_v = 5
lattice_ob.data.points_w = 5

bpy.context.view_layer.objects.active = lattice_ob
bpy.ops.lattice.select_all(action = 'SELECT')

for i in range(len(DIR7pointlist)):
    df = np.genfromtxt(os.path.join(DIR7point, DIR7pointlist[i]), delimiter=',')
    for j in range(len(df)):
        xx, yy, zz = df[j]
        r = 5
        bpy.ops.object.empty_add(type = 'SPHERE', radius = r, location = (xx, yy, zz))

bpy.ops.object.select_all(action = 'DESELECT')

for ob in collection.objects:
    if ob.type == "EMPTY":
        bpy.context.view_layer.objects.active = lattice_ob
        hookmod = lattice_ob.modifiers.new("Hook", 'HOOK')
        hookmod.falloff_radius = 1
        hookmod.falloff_type = 'SMOOTH'
        hookmod.object = ob

1 Answer 1


How to hook a vertex of a curve to a certain object?

modifier.vertex_indices_set( range(index_from, index_to) )

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.