How do I rename all object as same as their material name?
Name objects after active material
May or may not work as you expect.  All objects could share one material and hence renaming would end up with objects named &quot;Material&quot;, &quot;Material.001&quot;, ... following the blender naming convention for unique object names.
An object can have many materials.
Test script have renamed every object in scene after the name of its active material if it has one.
import bpy
from bpy import context
from bpy import data

# all objects
all_objects = data.objects
# scene objects
scene_objects = context.scene.objects
# selected objects
selected_objects = context.selected_objects

for ob in scene_objects:
    if ob.active_material:
        ob.name = ob.active_material.name

for all objects in blend edit and use
for ob in all_objects:
    ....

similarly for selected_objects