Force triangles only (or warn user) before exporting with built in blender functions I'm making an export script and I want only triangles (no quads or other polygons). To avoid wheel reinvention I'd like to call the "triangulate faces" command (ctrl t while object selected in edit mode) in order to force uniformity before exporting.

If that's not a supported feature I'd be fine popping up a dialog box of some sort warning the user that non triangles were found in the file and won't be included in the export (which I also don't know how to do.)

A working python example of either would be great.
this script triangulates a model.  If you are in Edit mode it will switch to Object mode before triangulation takes place.  If you add bpy.ops.object.mode_set(mode='EDIT') at the end of the script then it will return to Edit mode when completed. 

import bpy
import bmesh


if bpy.context.selected_objects:
    for obj in bpy.context.selected_objects:
        bpy.context.scene.objects.active = obj
        bpy.ops.object.mode_set(mode='OBJECT')

        obj = bpy.context.object
        me = obj.data

        bm = bmesh.new()
        bm.from_mesh(me)
        bmesh.ops.triangulate(bm, faces=bm.faces)

        bm.to_mesh(me)
        bm.free()
        del bm