5
$\begingroup$

I had a big project that I separated into smaller parts, but in every single file I now have all the images that I had in that one huge project earlier.

Unity has some problems with images linked to a project, so I want to keep it clean.

How can I delete all images from a project? I had a script that can delete unlinked images, but how do I unlink them all?

enter image description here

$\endgroup$
1
  • 6
    $\begingroup$ please stop shouting $\endgroup$
    – stacker
    Commented Jun 11, 2015 at 19:15

3 Answers 3

9
$\begingroup$

Combining this and this answers, one may get code like this:

    import bpy 

    for img in bpy.data.images:
        img.user_clear()

It will unlink all images in the .blend (one currently selected in the UV Image Editor will remain selected, but also will become unlinked, you can unlink one image by yourself or make improvement to the code).

Then you will only need to delete unlinked images.

The final code might look like this (thanks for evilferber's comment):

import bpy 
for img in bpy.data.images: 
  img.user_clear() 
for img in bpy.data.images: 
  if not img.users: 
    bpy.data.images.remove(img)
$\endgroup$
2
  • $\begingroup$ import bpy for img in bpy.data.images: img.user_clear() for img in bpy.data.images: if not img.users: bpy.data.images.remove(img) That's the script i needed ; ) $\endgroup$
    – evilferber
    Commented Jun 11, 2015 at 22:39
  • $\begingroup$ @Mr Zak Could you include evilferbers extension of the code in your answer please? $\endgroup$
    – Leander
    Commented Jan 12, 2017 at 20:17
1
$\begingroup$

Select the image in Image Editor and Shift + click the X Button. This will set the amount of users of that image to 0. When the file is saved the image will be discarded.

$\endgroup$
2
  • $\begingroup$ I don't want to delete one image at the time. I have a lots of projects with many many images. I'm not asking for a way to delete single image. $\endgroup$
    – evilferber
    Commented Jun 11, 2015 at 21:26
  • $\begingroup$ @evilferber time to get some coffee, I totally ignored the bold text in your question and didn't read the python tag :D $\endgroup$ Commented Jun 12, 2015 at 6:35
1
$\begingroup$

The following code will also work:

for img in bpy.data.images: 
   bpy.data.images.remove(img, do_unlink=True)
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .