Is there a way to get the number of material slots of a mesh?

sure, try this

127386-num+materials.png