You’re right, that’s what I did with my C# routine, it starts to get more complex as the solid become more complex,
for example when there are no 90* angles on the solid.
Dan, try something like this (pseudo code) -
Find the longest edge
get a face this edge belong to //(there are 2 choices, it doesn't matter at this stage)
// the zvec of the xfrom
vecz = edge.ep - edge.sp
vecz.normalise
// the y vec of the xform, as the face normal is perp to the face it's also perp to the edge
vecy = face.normal()
// now create the x vec for the xform
vecx = vecz.crossproduct(vecy)
// if you need to xlate it as well, get the vector to the sp (start point) of the edge
vectrans = edge.sp.asVector()
Now all you need to do is build your matrices and do the work, invert them to xform back if required. The length will be bbox max.z - minz
hth