How to toggle between Flat and Smooth shading during animation?
Animatable (custom property) toggle

import bpy

def toggle_shading(self, context=bpy.context):
    """Toggle smooth shading"""
    value = self["use_smooth"]
    if self.polygons[0].use_smooth is not value:
        for poly in self.polygons:
            poly.use_smooth = value

def frame_handler(scene):
    """Update shading on frame change"""
    for mesh in bpy.data.objects.data.meshes:
        try:
            toggle_shading(mesh)
        except KeyError:
            pass

bpy.types.Mesh.use_smooth = bpy.props.BoolProperty(
    description=toggle_shading.__doc__, update=toggle_shading)
bpy.app.handlers.frame_change_pre.append(frame_handler)



Paste the script above in the Text Editor, click Register and Run Script.


Text block name must end with ".py" to activate the register functionality (run script on load).

In the Properties Window, under Object Data, Add a custom property with Property Name use_smooth and Property Value of 0.


You can now animate this value the toggle smooth shading.