Alternative to detach by MatID
I'm looking for a script that will detach an object into separate objects based on material ID. However I usually work with weighted normals and a standard select and detach will break them. So it would be useful to have a script that first duplicates the object then selects the faces of the material ID, inverts the selection and then deletes. After that it repeats itself for each remaining material ID of the object. Any help would be much appreciated.