Set Material Name to Object name?

Hi. I need to import a lot of .obj files witch have assigned materials to all the objects and I need to set the name of the objects as the names of the materials they are assigned to or a part of the name of the material.

So for example, if an object have the material assigned “_x0023_BALUSTERPine_Chocofur.jpg1111.004”, I need to assign the name of this object as “Baluster”, and so on.

If somebody knows a way to create a macro or a script to do this task more automatically please help. (6.6 MB)

P.S. Will be useful also to find a way to strip down the names of the materials, from “_x0023_BALUSTERPine_Chocofur.jpg1111.004” to something like “Baluster_Pine”.