Python MXS Classof

def get_all_mats(model):
    materials = []
    dupe = rt.copy(model)
    rt.resetXForm(dupe)
    rt.collapseStack(dupe)
    material = dupe.material
    if rt.classOf(material) == rt.Multimaterial:
        for matID in xrange(material.numsubs):
            #see if we can select any faces for each material
            dupe.selectByMaterial(matID+1)
            faces = dupe.GetSelection(rt.name("Face"))
            numSelected = faces.numberset
            if numSelected > 0:
                materials.append({material[matID]: numSelected})
    elif rt.classOf(material) == rt.StandardMaterial:
        # if we only have one material we assume that it is on every face
        materials.append({material.name: dupe.mesh.numFaces})
    rt.delete(dupe)
    return materials
Hunin and Munin