Set/assign material ID by submaterial

Hi

I have several hundreds of objects (windows for a skyscraper) with all 4 same sub materials, but different multi sub material.
All faces/elements have the right material attached. But i want all elements, on all objects that have eg. window material to be eg. material ID 1 and so on.

So, i need a script that gives all faces/elements with a certain material a given material ID.

example, I want to select window sub material and "say" all faces with this material get material ID 3...

Se picture for explanation. The numbers represent Material ID, the color represent different materials. (top is before, lower is after)

Is this possible?
many thanks!

AttachmentSize
untitled-1.jpg574.91 KB