How do I create and view the tangents/bitangents for a mesh?

I have read some of the documentation, but I am extremely new to Blender Scripting (new as in I-just-started-an-hour-ago-new), and have no damned clue what I am doing.

I used “bpy.data.scenes[0].objects[“Cube”]” to access an object…but I can’t use the “calc_tangents” func with that
(that func is reserved for a different class?)…so I was hoping someone could help a noob out here…

It is a Mesh type method:
http://www.blender.org/documentation/blender_python_api_2_70a_release/bpy.types.Mesh.html?highlight=calc_tangent#bpy.types.Mesh.calc_tangents

ob = bpy.context.object
if ob.type == 'MESH':
    me = ob.data
    me.calc_tangents()

    for loop in me.loops:
        print(loop.tangent)

    me.free_tangents()

I had actually found that out after a little research, but I couldn’t figure out how to access the Mesh class…
Thanks very much. Going to use this to confirm the output of my personal T/BT parsing script…and to cheat
and get texturing in OpenGL running a lil quicker… :stuck_out_tongue:

Again, thanks!

Hmm…just noticed something.
I tried this out on a cube which I subdivided-smoothed once. Instead of coming out with a single tangent per normal/vertex,
I get a total of 144 tangents (look at the bottom of the notepad outpad):


Are the tangents output like seperate per vertex normals, and they must be averaged together to get the single tangent for any given vertex?