Hook Mesh to Empty Tree - Ezekial711/MonsterHunterWorldModding GitHub Wiki
The following code restablishes the Hook modifiers between meshes and the tree of empties. This is useful when adding (or removing) bones that one wishes to see how they react to armature changes.
def link_empties():
armature = {obj.name:obj for obj in C.scene.objects if obj.type = "EMPTY"}
meshes = [obj for obj in C.scene.objects if obj.type = "MESH"]
for ob in meshes:
modifierlist = {m.name for m in ob.modifiers if m.type == "HOOK"}
for bone in armature:
if armature[bone].name not in modifierlist:
modifier = ob.modifiers.new(name = armature[bone].name, type='HOOK')
modifier.object = armature[bone]
modifier.vertex_group = armature[bone].name
modifier.falloff_type = "NONE"
if not modifier.vertex_group:
ob.modifiers.remove(modifier)
else:
bpy.context.scene.objects.active = ob
ob.select = True
bpy.ops.object.mode_set(mode = 'EDIT')
bpy.ops.object.hook_reset(modifier = modifier.name)
bpy.ops.object.mode_set(mode = 'OBJECT')
ob.select = False
bpy.context.scene.objects.active = None