Maya How To Find Transform Matrix From Two Unit Axes(a Target and a Source)

Been Stuck on this weird situation, I have two unit axes, system unit axes and a target unit axes, and I want to recreate the transform matrix that when apply back using cmds.xform(), can rotate the system unit axes to the target axes.

code from chatGPT 4:

import maya.api.OpenMaya as om

# Define target unit vectors (A, B, C)
A = om.MVector(0.589392, -0.324572, -0.739777)
B = om.MVector(0.275346, 0.941617, -0.193756)
C = om.MVector(0.759475, -0.0894966, 0.644351)

# Construct the rotation matrix using vectors A, B, C
rotation_matrix = om.MMatrix([
    [A.x, B.x, C.x, 0],
    [A.y, B.y, C.y, 0],
    [A.z, B.z, C.z, 0],
    [0,   0,   0,   1]
])

# Construct the system unit axes
default_basis = om.MMatrix([
    [1, 0, 0, 0],
    [0, 1, 0, 0],
    [0, 0, 1, 0],
    [0, 0, 0, 1]
])

# multiplication
result_matrix = default_basis * rotation_matrix

cmds.xform("unit_axes", matrix=result_matrix)

But it ended up like in the image below shown in result, which doesn’t match the target axes

If I remember correctly, Maya uses row-major matrices. So your rotation matrix should be

rotation_matrix = om.MMatrix([
    [A.x, A.y, A.z, 0],
    [B.x, B.y, B.z, 0],
    [C.x, C.y, C.z, 0],
    [0,   0,   0,   1]
])

Now that does it, Thanks again~