Solidworks macro for Part files to create coordinate frames from 4x4 transforms and calculate relative transforms between coordinate frames. (not sure why it doesn't work for assemblies...tbd)
In the macro, there are two features: Create Relative Coordinate Frame and Calculate Relative Transform.

From the drop-down menu, you can select an existing coordinate frame from your feature tree. The order for the rotation matrix is the standard, normalized 3x3 matrix (column 1 is the x-axis, etc), and the order for translation is x, y, z (units in meters).
When you click Apply, the macro will create a new coordinate frame in your Part file with the 3D sketch used to instantiate it.
From the drop-down menu, you can select two existing coordinate frames from the feature tree to calculate the relative transform from the Base Transform to the Goal Transform. The relative transform will populate in the textbox below, following the standard homogeneous 4x4 matrix format:
Please refer to the Solidworks documentation for assigning this Macro to a Toolbar button: https://help.solidworks.com/2026/english/SolidWorks/sldworks/t_assigning_macro_toolbar_button.htm?id=1.13.7.6.0
Testing with data from trakSTAR ascension system. Two sensors, labeled frame_1 and frame_2, were used to record their 4x4 matrix position. A third matrix, calculated as the relative transform from frame_1 to frame_2, was defined as relative_frame. As expected, when relative_frame was applied to frame_1, it aligns perfectly with frame_2.
Note: the origin frame o was manually made as a separate coordinate frame, not the native Origin in the Part file.
