Transform (Rotate) with 4x4 matrix via python I have imported geometry that I am rigging for showing assembly of a product. The driving curves have been imported from rhino, from which I have built up the model further in Blender. 

As part of the animation, I would like to show how all the parts fit in a box, when they are flat. However, rotating each part by eye is proving difficult as each part is quite 3 dimensional. Thus, via Rhino, I have calculated the transform matrix needed for each part in order for it to be flat on the ground. 

I would like to use the data from this matrix to transform objects via python.

 

Update: Here is a simplified version:

, where the orange is the target.

Here is the output that I get from Rhnio python going from A to A':

R0=(-0.470458022353494,-0.807963312121372,0.354773921630525,-6631.4567921258), R1=(0.645229984870226,-0.589232780440685,-0.486295174846007,3943.31281557432), R2=(0.601953084407421,0.000129305847915359,0.798531444247745,2890.46728702281), R3=(0,0,0,1)

I make the following output into a python list and then set it to the updated matrix from above

import bpy
from mathutils import Matrix, Vector

obj = bpy.data.objects['Untitled'].pose.bones["topfrontleft"]

m =  (0.879972675860339,-0.0926548147745,0.465900391755896,-1329.45963312555), (0.443132751289856,-0.193193761313235,-0.875391075647866,1124.19004435354),(0.171118247050034,0.976775949687925,-0.128946848111055,3977.30420903923),(0,0,0,1)

m_new = Matrix(m)

obj.matrix = m_new


Here is a ling to the Blend file: http://1drv.ms/1X8vHXO
I took your blend file and modified the code a little bit. At first I inserted the R0, R1, R2 and R3 values into the matrix. Then to transform a given matrix with another one you have to multiply them. The order is important.

import bpy
from mathutils import Matrix

bone = bpy.data.objects['Untitled'].pose.bones["topfrontleft"]

m = [ (-0.470458022353494, -0.807963312121372,     0.354773921630525, -6631.4567921258),
      ( 0.645229984870226, -0.589232780440685,    -0.486295174846007,  3943.31281557432),
      ( 0.601953084407421,  0.000129305847915359,  0.798531444247745,  2890.46728702281),
      ( 0,                  0,                     0,                  1) ]

matrix = Matrix(m)
bone.matrix = matrix * bone.matrix


After executing the code in your file the bone is 'flat', but instead of being parallel to the x axis (so that it matches the other edge) it is parallel to the y axis.. Are you sure that the matrix is correct? If yes you will need some other matrices to rotate it in the correct direction, but at least it's already flat :D