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