Save objects automatic in its own blendfile with copy their name as file name

Hi everyone,
is it possible to automatic save each object in its own blendfile without copy the object in the new file and click save it the manuell way?

If its possible that Blender name the new blendfile after the object?

Why do I look for that?
I have like 300+ objects which I need in a separate blendfile for the assetmanager chocoflur.

Thanks for help

Dominik

possible with a script

loop on all selected objects then transfer to another file and save it with same name then object.

may be ask in python forum

I’m also interested in a script like that
let us know when you get one

thanks
happy bl

This is only possible with a script. I did that couple times in the past, and it is a bit involved, at least the way I did was convoluted. This was also something I wanted to make part of IoGuru, but never get around it unfortunately.

There could be multiple approaches but one way (two step process) is to make 300+ copies of your scene named with individual object name and then parse the scenes and delete everything else except the object that also shares the same name as the filename. This can be done with regular Python + Bpy module.

Here’s a naive script. The call at the end is a sample usage, will export selected objects into their own .blends. Don’t forget to substitute your desired directory path.

It won’t link every object to a scene (for example, if you give it an object with a modifier that uses object ‘Foo’, ‘Foo’ will also be exported but will not appear in the scene when you load the file, you’d have to link it to a collection manually if needed).

Use with caution, this will overwrite files without asking.

import bpy
import os
import tempfile

def export_objects_to_separate_blends(target_dir, objects):
    scene = bpy.data.scenes.new("Export")
    layer = scene.view_layers.new("View Layer")
    collection = bpy.data.collections.new("Export")
    layer.layer_collection.collection.children.link(collection)

    try:
        for o in objects:
            collection.objects.link(o)
            tmpf, tmpn = tempfile.mkstemp(dir=target_dir)
            bpy.data.libraries.write(tmpn, {scene})
            collection.objects.unlink(o)        
            os.close(tmpf)    
            os.replace(tmpn, os.path.join(target_dir, o.name.replace('.', '_') + ".blend"))
    finally:
        bpy.data.collections.remove(collection, do_unlink=True, do_id_user=True, do_ui_user=True)
        bpy.data.scenes.remove(scene, do_unlink=True)
        
export_objects_to_separate_blends("/your/target/directory", bpy.context.selected_objects)
1 Like

Thanks for the script Stan_Pancakes. Ill try it later. :+1:

Thanks everyone else too :+1:

@Stan_Pancakes,

I tried the script. It creates some temp files but not blend files. I add screenshots of the console and of the created files. Maybe you can help me.

folder
Thanks a lot for your help already :slight_smile:

Hm, that’d be tricky as I don’t have a dedicated Windows machine, let me see if Blender would even run in a VM…

@Stan_Pancakes,

for which Os is the script in Blender?
Are blendfiles different on different OS?

If you can give me the name of your OS I could install it and try it on it.