Python Script For Saving Materials

Hi All

Please can someone tell me what I am doing wrong with this python scripts ?

import unreal

def save_materials(file_path):
# Get all the static mesh actors in the world
static_mesh_actors = unreal.EditorLevelLibrary.get_all_actors_of_class(unreal.StaticMeshActor)

# Open the file for writing
with open(file_path, 'w') as file:
    for actor in static_mesh_actors:
        # Get the static mesh component of the actor
        static_mesh_component = actor.get_component_by_class(unreal.StaticMeshComponent)
        
        # Write the actor name
        file.write(f"{actor.get_name()}\n")
        
        # Write the materials applied to the static mesh
        for i in range(static_mesh_component.get_num_materials()):
            material = static_mesh_component.get_material(i)
            if material:
                material_path = material.get_path_name()
            else:
                material_path = "None"
            file.write(f"MaterialSlot{i}: {material_path}\n")
            
        # Separate each actor's material list with a newline
        file.write("\n")

Example usage

save_materials(“C:/downloads/materials.txt”)

Its just suppose to be saving materials from with in the level

Thanks