Python, How to get pose bone to rotate with another pose bone from a different armature? Finding Rotational difference I have two Armatures with different bone structure.
The goal is to get the rotational difference of one bone from a one Armature and translate it to the bone of the other Armature.

Code **For a General approach:
import bpy

context = bpy.context
scene = context.scene

Rig_1 = bpy.context.scene.objects['__Rig'] 
Rig_2 = bpy.context.scene.objects['__Rig2'] 

Rig_1_RightArm = Rig_1.pose.bones[&quot;r_uparm&quot;]
Rig_2_RightArm = Rig_2.pose.bones[&quot;r_uparm&quot;]

scene.frame_set(1)
WorldSpace_RightArm_1-1 = Rig1.matrix_world @ Rig_1_RightArm.matrix 

bpy.context.view_layer.update()

scene.frame_set(2)
WorldSpace_RightArm_1-2 = Rig1.matrix_world @ Rig_1_RightArm.matrix 
WorldSpace_RightArm_2-2 = Rig2.matrix_world @ Rig_2_RightArm.matrix 

bpy.context.view_layer.update()

I've tried multiple methods and would like to know what to do beyond here, like using rotation_difference to between WorldSpace_RightArm_1-1 from frame 1 and WorldSpace_RightArm_1-2 from frame 2.
Object.convert_space
As mentioned in previous answer there is a convenience method available on the object that converts space.
Rather than totally doing my head in by trying to make a rotation difference am going to

Convert source and target pose bone matrices to world space
Decompose them, ie get their world space location, rotation and scale parts.
Recompose the target world matrix to have rotation part of source
Convert this to pose space of target bone and set as matrix.

Test method.
import bpy
from mathutils import Matrix

def snap_rotation(source, target):
    Ms = source.id_data.convert_space(
        pose_bone=source,
        matrix=source.matrix,
        from_space='POSE',
        )
    Mt = target.id_data.convert_space(
        pose_bone=target,
        matrix=target.matrix,
        from_space='POSE',
        ) 
         
    _, q, _ = Ms.decompose()
    t, _, s = Mt.decompose()
    M = (
        Matrix.Translation(t) @
        q.to_matrix().to_4x4() @ 
        Matrix.Diagonal(s.to_4d())
        )
    target.matrix = target.id_data.convert_space(
        pose_bone=target,
        matrix=M,
        to_space='POSE',
        )    

if __name__ == &quot;__main__&quot;:
    context = bpy.context
    scene = context.scene
    snap_rotation(
        scene.objects[&quot;Armature&quot;].pose.bones[&quot;Bone&quot;],
        scene.objects[&quot;Armature.001&quot;].pose.bones[&quot;Bone&quot;]
    )