How to align an object so one of its faces are axis-aligned? (make an object upright for eg) I'm considering adding a feature to the 3d-printing tools, or to the Transform menu -- whichever is more appropriate.

Background: When 3d printing, one often must rotate an object so some face(s) lie flat on the xy plane, so it'll print flat.

Present method (which works, but is a lot of steps):


Select the desired face (in edit mode)
Shift+Numpad7 to view it from its local Top
Go to Object mode and add an Empty
Check Align to view (so the empty is aligned to the top-down view of the face)
Parent the object to the empty (empty becomes parent)
Select the empty and clear its rotation (Alt+R)
Select and unparent (Alt+P) the object, using Keep transformation
Success!


Desired methods:
A. Rotating the mesh in edit mode might be satisfactory, so:


Select face
Hit button (Make Face Bottom?) in 3d-Printing tools, which rotates the whole mesh so that face aims down.


Note: Sometimes someone may want to align so this is the top or side face, so the button might be better as: Align object to face, followed by a tool option which allows a selection of: "Top, bottom, left, right"



B. Rotating the object itself might also be desired by some, instead:


Select face
Shift+7 to view from face's "top"
Go to object mode
In the transform menu, select Align object view-rotation.  Tooltip: Rotates object to align the current view's rotation with an axis.(Or something more clear).
Tool-options allow overriding default of -Z with: Z-, Z+, Y-, Y+, X-, X+


Note: Tool-options may also allow a pulldown of the available Transform orientations, defaulting to global.



The easiest and fastest implementation might be a python addition to the 3d-printing tools, but I believe it worthwhile to consider the usefulness of this feature in normal modeling, and therefore its addition to the transform menu -- this has the secondary positive effect of it working on the object instead of the mesh, thereby retaining the object's local transform orientation.

Advice, suggestions, questions, or assistance are all welcome.
Blender doesn't have a tool built-in to perform this operation currently.

If you would write your own tool,
a method you can use to achieve this using Python.


Define the source vector (face normal in this case).
Define the destination vector (the axis vector).
Use the rotation between these vectors to define a 3D rotation(see Vector.rotation_difference).
Then rotate your object by this.


This example uses the normal of the first face, assumes object 

import bpy
from mathutils import Matrix, Vector

obj = bpy.context.object
matrix_orig = obj.matrix_world.copy()

# for this example just pick the first face.
axis_src = matrix_orig.to_3x3() * obj.data.polygons[0].normal
# z-axis, could be any direction
axis_dst = Vector((0, 0, 1))

matrix_rotate = matrix_orig.to_3x3()
matrix_rotate = matrix_rotate * axis_src.rotation_difference(axis_dst).to_matrix()
matrix_translation = Matrix.Translation(matrix_orig.to_translation())

obj.matrix_world = matrix_translation * matrix_rotate.to_4x4()