Python script for adding Child Of bone constraint with 'Set Inverse' to multiple bones? Completely new to scripting and was hoping someone would help me out here.

I've imported a rig twice and want to add a "Child Of" bone constraint to each bone in the first rig using the matching bone in the second rig as the target. I also want to use "Set Inverse" function of this constraint.



The rigs are the same, so all the bones are named the same.

Rigs are called "root" and "root.001".

I figure I need to do something with:

import bpy

context = bpy.context
scene = context.scene

rig1 = scene.objects.get("root")
rig2 = scene.objects.get("root.001")

for bone in rig1.pose.bones:
    cbone = bone
    cbname = bone.name
    setchild = bone.constraints.new(type='CHILD_OF')
    setchild.target = rig2
    setchild.subtarget = cbname


But beyond that I have no clue. I'm not sure how to set the inverse option.

I'm looking to edit a number of animation files, so would need to do this process for each fbx file, and therefore would love to automate the process.

Hoping someone can help me out.
Cheers.
import bpy

ob = bpy.context.active_object

# Take a copy of current layers 
org_layers = ob.data.layers[:]

# Show all layers
for i in range(len(org_layers)):
    ob.data.layers[i] = True

for b in ob.pose.bones:
    for c in b.constraints: 
        if c.type == "CHILD_OF":
            context_py = bpy.context.copy()
            context_py["constraint"] = c
            ob.data.bones.active = b.bone
            bpy.ops.constraint.childof_set_inverse(context_py, constraint="Child Of", owner='BONE')

# Reset back to orginal layer state    
for i in range(len(org_layers)):
    ob.data.layers[i] = org_layers[i]


Found by Ratt, cheers guys! (let me know if this is what you meant)!