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.
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)