#Multiple objects
There are a couple ways I can think of. One way is to use custom transform orientationscustom transform orientations.
- In edit mode (↹ Tab), select the edge that you want to align the object to and press ⎈ Ctrl⎇ AltSpace to create a new transform orientation.
The manipulator widget should align to the edge and you should see the selected transform orientation switch to the new custom one in 3D view > header:
- In object mode, select the object you wish to align and press Align to transform orientation in 3D view > Header > Object > Transform:
- Your object's local X Y and Z axes will be aligned to the active transform orientation. This is probably not exactly what you want. In your case, since you just want to adjust the rotation of the first object around the Z, set the rotation along the other two axes to 0:
- Now we are closer, but still off by 90° around the Z. To fix this, just add 90:
#Single mesh
You might be able to use custom transform orientations here too, but here's a different way just to mix it up:
What I did in the gif:
Snap one vertex on the transforming edge to a vertex on the target edge.
Snap the 3D cursor to the vertex which was just snapped to (⇧ ShiftS> cursor to selection)
Set the pivot to the 3D cursor (.)
Set the snapping target to edge and rotate the mesh (R) until it snaps into place.
You should be able to apply this approach to multiple objects too.