parenting same material

Dear all,
I have a 3d obj of a machinery, with thousand of objects and thousand of materials (panels, screws, glasses), it is really complex.
I’ve received it from my technical department and my aim is to render it.

I tried to join the meshes with the same material (Shift + L, join) but it’s a huge work, there a re too many objects and too many materials.

I’ve tried some scripts in Python (I’m not a programmer) found on the web, but I think they don’t fit my situation.

What I’m looking for is a script that search and make parents that objects that has the same material automatically (without giving any initials or materials name)…

any kind of help will be really appreciate…

thanks in advance
Best regards
Alberto

Could you elaborate a bit more on specifically what you are trying to do? Do the objects each only have one material?

If they all only have one material applied, would this work for what you are trying to do?

  1. Loop through all materials in the scene.
  2. For each material, select all the objects in the scene with this material as the active material.
  3. Create a new empty object and give it the name of the material.
  4. Parent the selected objects to this empty.