Take the 2-minute tour ×
Blender Stack Exchange is a question and answer site for people who use Blender to create 3D graphics, animations, or games. It's 100% free, no registration required.

with a large projects that have hundreds of textures, it can be very difficult to deal with them in the UV image editor using the following little drop-down menu.
enter image description here

The best solution that I've come with so far is to modify the UV Image Editor code using some code from the Sculpt and Texture Paint section which is very helpful but it's still difficult to tell if something is in use and it has to be reopened every time something is selected and deleted.

(It now looks like the following in case anyone is interested. You can do this by menu-clicking the image icon next to New and Open then selecting edit source and changing the following line in space_image.py

layout.template_ID(sima, "image", new="image.new", open="image.open")

to be

layout.template_ID_preview(sima, "image", new="image.new", open="image.open", rows=8, cols=16)

enter image description here

There is the following page which deals with deleting textures and it's what I do already but it's time consuming and very difficult to find the unused textures when there are a couple hundred of them, especially if the drop down menu has to be reopened and searched for everyone one of them.

How can I delete unused data blocks from my Blender Project?

So my question is the this: Is there a way to delete all the unused textures using a Python script?

I have found one script that has a really evil sounding name and I don't want to write it here but it does not work very well. Sometimes it does and sometimes it does not.
This gives the impression that there is something going on behind the scenes when it comes to how textures are considered to be in use.

By the way, I don't use Fake User or pack images so this may simplify things a bit,

Thanks for your consideration on this matter.

share|improve this question
    
If the datablocks are unused, they should be cleared out when you reload the .blend.. –  gandalf3 Jul 8 at 9:08
    
The problem is having to reopen and search the menu over and over again since it closes when something is selected. Also, it's not always clear what needs to go just from looking. –  MarcClintDion Jul 8 at 9:26
    
I'm not sure I understand.. Couldn't you just save the .blend and re-open it? (Ctrl+S, then Ctrl+Shift+O 1) That should clear out all datablocks with no users. –  gandalf3 Jul 8 at 17:46
    
I do that but it does not work all the time. I've even tried deleting every last object from the scene, saving, then reloading it, but most of the textures were still there even though there were not any models. This works fine for removing materials but textures are really hard to get rid of. –  MarcClintDion Jul 9 at 2:18
    
I just tried what I said about deleting all the objects, then saving and reloading. Most, or all the textures were still there, but when I fully shutdown Blender and reloaded the empty scene then only 17 of the textures are still there. I guess this should be a bug report. (This is without using the posted script). When I ran the script, another 12 disappeared right away. 3 were loaded from Texture Paint and 2 were from a model that was not there. –  MarcClintDion Jul 9 at 23:57

1 Answer 1

up vote 4 down vote accepted

Remove all images with zero users from the blendfile:

import bpy

for img in bpy.data.images:
    if not img.users:
        bpy.data.images.remove(img)
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.