Delete used and unused textures script

Hi everyone,

I would want to delete all textures, used and unused with an script but I couldn’t find it. Could anyone share this script in this post please?

Thanks a lot!

discard all environment maps in the blend file and free them from memory:

bpy.ops.texture.envmap_clear_all()

I do not know if this works.

You can not discard used textures. To do that you have to unlink them from the sources that are using them. Essentially create one material with no textures and assign it to all the objects in the scene. Then loop through all textures and try to remove them from memory.

Also, as a 1 post user you may be confusing Material with texture, maybe not. Materials have texture slots. Textures are linked to materials, but they can also be used by modifiers. If a texture has a user count > 0 then it can not be removed from memory. To be entirely thorough you would have to examine all the material texture slots, all the objects, all the modifier and the world environment to make sure all textures were not linked to any of those datablocks.

Are you trying to achieve a specific goal or are you just trying to learn the API?