I'm trying to create a .blend file that saves the scene, but I would like the image files to be separate, so I created a script that saves the bpy.data.images image files in a folder next to the .blend file. like to :

import os, shutil
def save_images(folder_path,my_image_list):
    for i in my_image_list:
        if not i.file_format:
            i.file_format = 'PNG'     
        image_path = os.path.join(folder_path,i.name)
        if not os.path.isfile(i.filepath):
            filepath_raw = i.filepath
            i.filepath_raw = image_path
            i.filepath_raw = filepath_raw

So everything works beautifully, except for the fact that if I have a "packed image", a large file will be saved, therefore useless, as I already have the necessary images alongside that project.


I wanted to figure out how to be able to write the project with bpy.data.libraries.write() without it also writing packed images if there are any.

I am aware that I can check them with bpy.data.images['My Image'].packed_file, which returns if the image is packed.

I could write something that unpack temporarily, but I see it as risky.

  • $\begingroup$ "I'm trying to create a blend file that saves the scene" - Does this mean you got a blend file and trying to create a second blend file just without the images packed? Or generating a blend from a certain scene without the images packed? $\endgroup$ – brockmann Oct 7 '20 at 7:53
  • $\begingroup$ I try to create a .blend file, in which the images are not Packed (This unfortunately happens if some images are packed, so they will also be packed in the new "file.blend") I don't know if I can explain myself well $\endgroup$ – Noob Cat Oct 7 '20 at 9:13
  • $\begingroup$ Get it. The contents of the blend you wanna create are coming from another blend? If so how do you copy the data? $\endgroup$ – brockmann Oct 7 '20 at 9:21
  • $\begingroup$ I created a function that - Unpack or Copy - the files in a folder next to the "file.blend" that will be created. This Function understands if the file is packed, or is available in a path. Should I show this function? I didn't want to make the question very complicated, as the function takes into consideration a list of images, but not all those of the bpy.data.images $\endgroup$ – Noob Cat Oct 7 '20 at 9:41
  • 1
    $\begingroup$ I updated the question, Idea: For example, I select 3 objects, and I execute my operator, this creates a data_block and writes the 3 objects with bpy.data.libraries.write(). Through another function, a scan of all possible images contained in the materials is performed. Then comes the function that saves all the images in a separate folder (As you can see in the edited question). So the problem remains that even the images packed in the "file.blend" will be written. Which I would like not to happen, as the images will already be placed side by side with the "file.blend". $\endgroup$ – Noob Cat Oct 7 '20 at 9:53

Check the data

Chances are the objects are saved to the library blend, . but are not linked to any scene, or collection, hence the file appears empty when opened.

Check the library files bpy.data.object collection to confirm.

Consider adding the scene datablock to the library.

You can try this. I don't know much about...


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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