Joint orientation matching. Is there any good resources out there?

Hey guys I’m currently wondering if there is a way to match joint orientations to an edge of a Polygon(normals average), and if there are any resources out there that could automate this process would be stellar. An example of this would be like this:
. If you guys could point me to the right direction that would be amazing. Thanks for the time and look. (woops left looking in there twice. I must be really tired lol.)

I had a little fun with this and wrote a script that will do this automatically. Great exercise.

Here is the link to my blog where you can download the script : http://www.robotsquids.blogspot.com/2013/12/align-joint-to-edge-script.html
I used pymel so make sure you have it installed. (it comes shipped with Maya 2014)

Omg your a prince among men TY TY!

No problem. I enjoyed writing the script.

did something similar a while ago for orienting an object to another objects face:
http://perryleijten.com/download/workPlaneChanger.py

might give you a few extra ideas/options