Exporting multiple objects to multiple OBJ files

I have a large project I’m working on that is essentially made up for several hundred small pieces. I need to have each of these pieces as separate .obj files.

Obviously, I have the export selected addon, but is there an addon that allows me to export all scene objects into separate .obj files?

Having to go through and export each single piece would take an excruciatingly long time, so I would really like to avoid that.

I’ve done some searching on google, but everything I’ve found would require me to know something of programing… and that isn’t in my skillset at all.

The script below exports al objects in the scene, with the name Scene (default scene name in Blender), to seperate obj file, with the object name as filename. The destination folder is in the variable destfolder, here C: est. The folder must exists.
Important: always use double backslashes and it must end with two backslashes.
Usage: Open in Blender the text editor, click on New and paste the script. Then click Run Script.

import bpy

destfolder = "C:\	est\\"

sce = bpy.data.scenes['Scene']
for ob in sce.objects:
    bpy.ops.object.select_pattern(pattern = ob.name)
    bpy.ops.export_scene.obj(filepath = destfolder + ob.name + ".obj", use_selection = True)

Hello there, just writing here to not create a new thread unnecessary.

I was searching for such script as well and I have found explanations >here< and >here<. But I was struggling with some errors (I didn’t understand what I was supposed to do exactly), so here are two ready scripts made from all those examples for you guys to not waste your time trying to understand instructions from stackexchange forums:

First code works fast and exports all meshes including other layers. The second one works slow and exports only selected meshes. I, personally, like to use the first one, even if Blender will export objects from other layers. It is faster to delete them in folder, than to wait for the second script to export only selected meshes, it is really slow.

Have fun!

Export all objects as .OBJ:

import bpy

# get the path where the blend file is located
destfolder="C:\\Users\YourNameHere\Desktop\\"


# deselect all objects
bpy.ops.object.select_all(action='DESELECT')    


# loop through all the objects in the scene
scene = bpy.context.scene
for ob in scene.objects:
    # make the current object active and select it
    
    scene.objects.active = ob
    ob.select = True
    


    # make sure that we only export meshes
    if ob.type == 'MESH':
        # export the currently selected object to its own file based on its name
         bpy.ops.export_scene.obj(filepath = destfolder + ob.name + ".obj", use_selection = True)
    # deselect the object and move on to another if any more are left
    ob.select = False

Export selected objects as .OBJ:

import bpy

# get the path where the blend file is located
destfolder="C:\\Users\YourNameHere\Desktop\\"


# deselect all objects
# bpy.ops.object.select_all(action='DESELECT')    


# loop through all the objects in the scene
scene = bpy.context.scene
for ob in bpy.context.selected_objects:
    # make the current object active and select it
    
    scene.objects.active = ob
    ob.select = True
    


    # make sure that we only export meshes
    if ob.type == 'MESH':
        # export the currently selected object to its own file based on its name
         bpy.ops.export_scene.obj(filepath = destfolder + ob.name + ".obj", use_selection = True)
    # deselect the object and move on to another if any more are left
    ob.select = False

For the life of me I cant get this to work… Is there anychance you can do a video or a gif how this works?

Hi Daniel, I think it’s old code. In the current Blender version 2.9x, if you switch to the Scripting tab, there’s a built-in script called batch_export.py (Templates - Python - Batch Export). It’ll work with the current scene without specifying the file location. It’ll save the objects wherever your script is saved. Hope this helps!

1 Like