Save each object to separate .blend file

Any addon that works on Blender 2.92 for exporting each object on scene or selected to a separate .blend file?
I have tested this, but it does nothing on 2.92.
There is also this, but it appears to only export the selected into a single different .blend file, instead of separate ones.

A different solution to my problem would be to have a script that batch converts .obj files to .blend, since I already have a script for exporting every object into a separate .obj, but I have 0 python skills as of now.

The following code should get you started; but can likely be improved upon.
As opposed to trying to separate items in an open blend file this finds the items in a closed blend file, appends them to the current file and saves it as its own file based on naming convention of the file the object was appended from and the object name.
It will create a subfolder named from the original blend file then create blend files in the subfolder for each object appended from the original blend file. This was done on windows and has a couple hard coded path lines so if you are on mac or other you will need to adjust those.

import bpy
import os


# folder containing blend files
my_dir = "C:\\Blender Projects\\bridge\\"
# all blend files in directory
blendfiles = [f for f in  os.listdir(my_dir) if f.split(sep=".")[-1] == "blend"]

def get_object_names(assets_path):
    names = []
    with bpy.data.libraries.load(assets_path) as (data_from, data_to):
        names = [name for name in data_from.objects]
    return names

for file in blendfiles:
    # prep to make a folder based on blend file name
    newfolder = os.path.join(my_dir, file.split(sep=".")[0])
    filepath = os.path.join(my_dir, file)
    # make a folder based on blend file name to store new files
    if not os.path.isdir(newfolder):
        os.mkdir(newfolder)
    # get each object from blend file
    objs = get_object_names(filepath)
    for obj in objs:
        # clear the current file
        while len(bpy.data.objects) > 0:
            bpy.data.objects.remove(bpy.data.objects[0])
        override = bpy.context.copy()
        override["area.type"] = ['OUTLINER']
        override["display_mode"] = ['ORPHAN_DATA']
        bpy.ops.outliner.orphans_purge(override, 4)
        # append the object
        bpy.ops.wm.append(filepath=file, directory=str(filepath)+"\\Object\\", filename=obj)
        # save blend file
        bpy.ops.wm.save_as_mainfile(filepath=os.path.join(newfolder, obj+".blend"))
1 Like

Perfect. Thank you.

For those that find this thread later on, here is a variant that unpacks textures to save space for files that have many objects sharing the same textures. The script should be run on a new, empty and unsaved blend file, and should target blend files that have textures packed on them (done via File > External Data > Pack all into .blend). Tested on Blender 2.90, Windows 10.


import bpy

import os

# folder containing blend files

my_dir = r"C:\MyFolderLocation"

# all blend files in directory

blendfiles = [f for f in  os.listdir(my_dir) if f.split(sep=".")[-1] == "blend"]

def get_object_names(assets_path):

    names = []

    with bpy.data.libraries.load(assets_path) as (data_from, data_to):

        names = [name for name in data_from.objects]

    return names

for file in blendfiles:

    # prep to make a folder based on blend file name

    newfolder = os.path.join(my_dir, file.split(sep=".")[0])

    filepath = os.path.join(my_dir, file)

    # make a folder based on blend file name to store new files

    if not os.path.isdir(newfolder):

        os.mkdir(newfolder)

    # get each object from blend file

    objs = get_object_names(filepath)

    for obj in objs:

        # clear the current file

        while len(bpy.data.objects) > 0:

            bpy.data.objects.remove(bpy.data.objects[0])

        override = bpy.context.copy()

        override["area.type"] = ['OUTLINER']

        override["display_mode"] = ['ORPHAN_DATA']

        bpy.ops.outliner.orphans_purge(override, 4)

        # append the object

        bpy.ops.wm.append(filepath=file, directory=str(filepath)+"\\Object\\", filename=obj)

        # save blend file

        bpy.ops.wm.save_as_mainfile(filepath=os.path.join(newfolder, obj+".blend"))

        # unpack_textures

        bpy.ops.file.unpack_all(method='USE_LOCAL')

        # save blend file again

        bpy.ops.wm.save_mainfile()

Here is a similar script that converts .glb files in a folder into .blend files.


import bpy

import os

# folder containing glb files

my_dir = r"C:\MyFolderLocation"

# all glb files in directory

glbfiles = [f for f in  os.listdir(my_dir) if f.split(sep=".")[-1] == "glb"]

for file in glbfiles:

    here = os.path.join(my_dir, file)

    bpy.ops.import_scene.gltf(filepath=here, import_pack_images=True) 

   # remove orphans from glb file

    override = bpy.context.copy()

    override["area.type"] = ['OUTLINER']

    override["display_mode"] = ['ORPHAN_DATA']

    bpy.ops.outliner.orphans_purge(override, 4) 

    # get object name

    obj = bpy.context.scene.objects[0].name

    # save blend file

    bpy.ops.wm.save_as_mainfile(filepath=os.path.join(my_dir, obj+".blend"))

    # clear the current file

    while len(bpy.data.objects) > 0:

        bpy.data.objects.remove(bpy.data.objects[0])

    override = bpy.context.copy()

    override["area.type"] = ['OUTLINER']

    override["display_mode"] = ['ORPHAN_DATA']

    bpy.ops.outliner.orphans_purge(override, 4)

Change occurrences of glb to gltf for the latter. Keep “bpy.ops.import_scene.gltf” regardless.

not sure if you’ve seen this or not, but I’ve been using it for the past few weeks and it’s great: https://github.com/CGCookie/io_export_blend

1 Like

Hi i desperately try to find a wayy to batch export individual objects at once, and none of the solutions here are working for me, i’m on windows10 v2.93.0

sawed this topic https://blender.community/c/rightclickselect/VCfbbc/?sorting=hot it looks like there is no definite solution for something relatively simple.