1
$\begingroup$

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.data.collections['Collection'].objects.link(lattice_ob)
bpy.context.view_layer.objects.active = lattice_ob
lattice_ob.select_set(True)
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.lattice.select_all(action = 'SELECT')
bpy.ops.object.mode_set(mode='OBJECT')


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))
    break

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

for ob in collection.objects:
    if ob.type == "EMPTY":
        bpy.context.view_layer.objects.active = lattice_ob
        lattice_ob.select_set(True)
        ob.select_set(True)
        bpy.ops.object.mode_set(mode='EDIT')
        
        hookmod = lattice_ob.modifiers.new("Hook", 'HOOK')
        hookmod.falloff_radius = 1
        hookmod.falloff_type = 'SMOOTH'
        hookmod.object = ob
        bpy.ops.object.mode_set(mode='OBJECT')
$\endgroup$

1 Answer 1

1
$\begingroup$

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

modifier.vertex_indices_set( range(index_from, index_to) )
$\endgroup$

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.