Skip to main content
Blender 2.8+, Blender 3.1+
Source Link
p2or
  • 16.1k
  • 10
  • 87
  • 146

Blender 3.1+

As of Blender 3.1.0 the name of the operator has been changed to obj_export() and is now part of the WindowManager namespace bpy.ops.wm.obj_export(filepath="//"):

import bpy
import os

# getGet the path where the blend file is located
basedir = bpy.path.abspath('//')

# deselectDeselect 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:
    # makeSelect each object
    ob.select_set(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.wm.obj_export(
            filepath=os.path.join(basedir, ob.name + '.obj'),
            export_selected_objects=True,
            )
    # Deselect the object and move on to another if any more are left
    ob.select_set(False)

Blender 2.8+

As of Blender 2.8.0 the selection attribute (Object.select) has been removed in favor of get/set functions Object.select_set(State) and Object.select_get() to set and get the current selection state of each object:

import bpy
import os

# Get the path where the blend file is located
basedir = bpy.path.abspath('//')

# 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:
    # Select each object
    ob.select_set(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=os.path.join(basedir, ob.name + '.obj'),
                use_selection=True,
                )
    # Deselect the object and move on to another if any more are left
    ob.select_set(False)

Blender 2.7x

import bpy
import os

# Get the path where the blend file is located
basedir = bpy.path.abspath('//')

# 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
    
    # makeMake sure that we only export meshes
    if ob.type == 'MESH':
        # exportExport the currently selected object to its own file based on its name
        bpy.ops.export_scene.obj(
                filepath=os.path.join(basedir, ob.name + '.obj'),
                use_selection=True,
                )
    # deselectDeselect the object and move on to another if any more are left
    ob.select = False

To further tweak your export options, see the parameters that bpy.ops.export_scene_obj()bpy.ops.export_scene_obj() accepts. For example, you can include normals with use_normals=True, change forward axis with axis_forward etc.

 
# removeRemove
bpy.ops.object.select_all(action='DESELECT')
# changeChange to this where instead of the entire scene, we only look through selected objects
for ob in bpy.context.selected_objects:
for ob in scene.objects:
    # addAdd the check to see if in selected objects here
    if ob in bpy.context.selected_objects:
        # adjust indentation
        ...
        ...
import bpy
import os

# get the path where the blend file is located
basedir = bpy.path.abspath('//')

# 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=os.path.join(basedir, ob.name + '.obj'),
                use_selection=True,
                )
    # deselect the object and move on to another if any more are left
    ob.select = False

To further tweak your export options, see the parameters that bpy.ops.export_scene_obj() accepts. For example, you can include normals with use_normals=True, change forward axis with axis_forward etc.

# remove
bpy.ops.object.select_all(action='DESELECT')
# change to this where instead of the entire scene, we only look through selected objects
for ob in bpy.context.selected_objects:
for ob in scene.objects:
    # add the check to see if in selected objects here
    if ob in bpy.context.selected_objects:
        # adjust indentation
        ...
        ...

Blender 3.1+

As of Blender 3.1.0 the name of the operator has been changed to obj_export() and is now part of the WindowManager namespace bpy.ops.wm.obj_export(filepath="//"):

import bpy
import os

# Get the path where the blend file is located
basedir = bpy.path.abspath('//')

# 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:
    # Select each object
    ob.select_set(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.wm.obj_export(
            filepath=os.path.join(basedir, ob.name + '.obj'),
            export_selected_objects=True,
            )
    # Deselect the object and move on to another if any more are left
    ob.select_set(False)

Blender 2.8+

As of Blender 2.8.0 the selection attribute (Object.select) has been removed in favor of get/set functions Object.select_set(State) and Object.select_get() to set and get the current selection state of each object:

import bpy
import os

# Get the path where the blend file is located
basedir = bpy.path.abspath('//')

# 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:
    # Select each object
    ob.select_set(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=os.path.join(basedir, ob.name + '.obj'),
                use_selection=True,
                )
    # Deselect the object and move on to another if any more are left
    ob.select_set(False)

Blender 2.7x

import bpy
import os

# Get the path where the blend file is located
basedir = bpy.path.abspath('//')

# 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=os.path.join(basedir, ob.name + '.obj'),
                use_selection=True,
                )
    # Deselect the object and move on to another if any more are left
    ob.select = False

To further tweak your export options, see the parameters that bpy.ops.export_scene_obj() accepts. For example, you can include normals with use_normals=True, change forward axis with axis_forward etc.

 
# Remove
bpy.ops.object.select_all(action='DESELECT')
# Change to this where instead of the entire scene, we only look through selected objects
for ob in bpy.context.selected_objects:
for ob in scene.objects:
    # Add the check to see if in selected objects here
    if ob in bpy.context.selected_objects:
        # adjust indentation
        ...
        ...
added the missing import instruction 'import os', needed for 'filepath=os.path.join(basedir, ob.name + '.obj')'
Source Link

There doesn't exist a way to do this in the options of the obj importer so what you could do is run a script that loops over the items in your scene, check if it is a mesh and export the current selection to its own file relative to the path your blend file is saved.

import bpy
import os

# get the path where the blend file is located
basedir = bpy.path.abspath('//')

# 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=os.path.join(basedir, ob.name + '.obj'),
                use_selection=True,
                )
    # deselect the object and move on to another if any more are left
    ob.select = False

To further tweak your export options, see the parameters that bpy.ops.export_scene_obj() accepts. For example, you can include normals with use_normals=True, change forward axis with axis_forward etc.

There are more stringent checks that could be made but for simple use cases and if used properly, this should suffice.

Also see How to batch import Wavefront OBJ files?.

To have it export only selected objects, comment line 7 and change line 11.

# remove
bpy.ops.object.select_all(action='DESELECT')
# change to this where instead of the entire scene, we only look through selected objects
for ob in bpy.context.selected_objects:

or keep line 11 and add another line

for ob in scene.objects:
    # add the check to see if in selected objects here
    if ob in bpy.context.selected_objects:
        # adjust indentation
        ...
        ...

NB: Make sure the layers you have objects on are selected otherwise you will just get an empty file.

There doesn't exist a way to do this in the options of the obj importer so what you could do is run a script that loops over the items in your scene, check if it is a mesh and export the current selection to its own file relative to the path your blend file is saved.

import bpy

# get the path where the blend file is located
basedir = bpy.path.abspath('//')

# 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=os.path.join(basedir, ob.name + '.obj'),
                use_selection=True,
                )
    # deselect the object and move on to another if any more are left
    ob.select = False

To further tweak your export options, see the parameters that bpy.ops.export_scene_obj() accepts. For example, you can include normals with use_normals=True, change forward axis with axis_forward etc.

There are more stringent checks that could be made but for simple use cases and if used properly, this should suffice.

Also see How to batch import Wavefront OBJ files?.

To have it export only selected objects, comment line 7 and change line 11.

# remove
bpy.ops.object.select_all(action='DESELECT')
# change to this where instead of the entire scene, we only look through selected objects
for ob in bpy.context.selected_objects:

or keep line 11 and add another line

for ob in scene.objects:
    # add the check to see if in selected objects here
    if ob in bpy.context.selected_objects:
        # adjust indentation
        ...
        ...

NB: Make sure the layers you have objects on are selected otherwise you will just get an empty file.

There doesn't exist a way to do this in the options of the obj importer so what you could do is run a script that loops over the items in your scene, check if it is a mesh and export the current selection to its own file relative to the path your blend file is saved.

import bpy
import os

# get the path where the blend file is located
basedir = bpy.path.abspath('//')

# 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=os.path.join(basedir, ob.name + '.obj'),
                use_selection=True,
                )
    # deselect the object and move on to another if any more are left
    ob.select = False

To further tweak your export options, see the parameters that bpy.ops.export_scene_obj() accepts. For example, you can include normals with use_normals=True, change forward axis with axis_forward etc.

There are more stringent checks that could be made but for simple use cases and if used properly, this should suffice.

Also see How to batch import Wavefront OBJ files?.

To have it export only selected objects, comment line 7 and change line 11.

# remove
bpy.ops.object.select_all(action='DESELECT')
# change to this where instead of the entire scene, we only look through selected objects
for ob in bpy.context.selected_objects:

or keep line 11 and add another line

for ob in scene.objects:
    # add the check to see if in selected objects here
    if ob in bpy.context.selected_objects:
        # adjust indentation
        ...
        ...

NB: Make sure the layers you have objects on are selected otherwise you will just get an empty file.

replaced http://blender.stackexchange.com/ with https://blender.stackexchange.com/
Source Link

There doesn't exist a way to do this in the options of the obj importer so what you could do is run a script that loops over the items in your scene, check if it is a mesh and export the current selection to its own file relative to the path your blend file is saved.

import bpy

# get the path where the blend file is located
basedir = bpy.path.abspath('//')

# 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=os.path.join(basedir, ob.name + '.obj'),
                use_selection=True,
                )
    # deselect the object and move on to another if any more are left
    ob.select = False

To further tweak your export options, see the parameters that bpy.ops.export_scene_obj() accepts. For example, you can include normals with use_normals=True, change forward axis with axis_forward etc.

There are more stringent checks that could be made but for simple use cases and if used properly, this should suffice.

Also see How to batch import Wavefront OBJ files?How to batch import Wavefront OBJ files?.

To have it export only selected objects, comment line 7 and change line 11.

# remove
bpy.ops.object.select_all(action='DESELECT')
# change to this where instead of the entire scene, we only look through selected objects
for ob in bpy.context.selected_objects:

or keep line 11 and add another line

for ob in scene.objects:
    # add the check to see if in selected objects here
    if ob in bpy.context.selected_objects:
        # adjust indentation
        ...
        ...

NB: Make sure the layers you have objects on are selected otherwise you will just get an empty file.

There doesn't exist a way to do this in the options of the obj importer so what you could do is run a script that loops over the items in your scene, check if it is a mesh and export the current selection to its own file relative to the path your blend file is saved.

import bpy

# get the path where the blend file is located
basedir = bpy.path.abspath('//')

# 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=os.path.join(basedir, ob.name + '.obj'),
                use_selection=True,
                )
    # deselect the object and move on to another if any more are left
    ob.select = False

To further tweak your export options, see the parameters that bpy.ops.export_scene_obj() accepts. For example, you can include normals with use_normals=True, change forward axis with axis_forward etc.

There are more stringent checks that could be made but for simple use cases and if used properly, this should suffice.

Also see How to batch import Wavefront OBJ files?.

To have it export only selected objects, comment line 7 and change line 11.

# remove
bpy.ops.object.select_all(action='DESELECT')
# change to this where instead of the entire scene, we only look through selected objects
for ob in bpy.context.selected_objects:

or keep line 11 and add another line

for ob in scene.objects:
    # add the check to see if in selected objects here
    if ob in bpy.context.selected_objects:
        # adjust indentation
        ...
        ...

NB: Make sure the layers you have objects on are selected otherwise you will just get an empty file.

There doesn't exist a way to do this in the options of the obj importer so what you could do is run a script that loops over the items in your scene, check if it is a mesh and export the current selection to its own file relative to the path your blend file is saved.

import bpy

# get the path where the blend file is located
basedir = bpy.path.abspath('//')

# 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=os.path.join(basedir, ob.name + '.obj'),
                use_selection=True,
                )
    # deselect the object and move on to another if any more are left
    ob.select = False

To further tweak your export options, see the parameters that bpy.ops.export_scene_obj() accepts. For example, you can include normals with use_normals=True, change forward axis with axis_forward etc.

There are more stringent checks that could be made but for simple use cases and if used properly, this should suffice.

Also see How to batch import Wavefront OBJ files?.

To have it export only selected objects, comment line 7 and change line 11.

# remove
bpy.ops.object.select_all(action='DESELECT')
# change to this where instead of the entire scene, we only look through selected objects
for ob in bpy.context.selected_objects:

or keep line 11 and add another line

for ob in scene.objects:
    # add the check to see if in selected objects here
    if ob in bpy.context.selected_objects:
        # adjust indentation
        ...
        ...

NB: Make sure the layers you have objects on are selected otherwise you will just get an empty file.

woops
Source Link
iKlsR
  • 43.7k
  • 12
  • 157
  • 190
Loading
added 78 characters in body
Source Link
ideasman42
  • 48k
  • 10
  • 144
  • 226
Loading
added 105 characters in body
Source Link
iKlsR
  • 43.7k
  • 12
  • 157
  • 190
Loading
deleted 10 characters in body
Source Link
iKlsR
  • 43.7k
  • 12
  • 157
  • 190
Loading
added 288 characters in body
Source Link
iKlsR
  • 43.7k
  • 12
  • 157
  • 190
Loading
added 288 characters in body
Source Link
iKlsR
  • 43.7k
  • 12
  • 157
  • 190
Loading
deleted 10 characters in body
Source Link
ideasman42
  • 48k
  • 10
  • 144
  • 226
Loading
deleted 74 characters in body
Source Link
iKlsR
  • 43.7k
  • 12
  • 157
  • 190
Loading
added 122 characters in body
Source Link
iKlsR
  • 43.7k
  • 12
  • 157
  • 190
Loading
added 282 characters in body
Source Link
iKlsR
  • 43.7k
  • 12
  • 157
  • 190
Loading
Post Undeleted by iKlsR
Post Deleted by iKlsR
Post Undeleted by iKlsR
deleted 5 characters in body
Source Link
iKlsR
  • 43.7k
  • 12
  • 157
  • 190
Loading
Post Deleted by iKlsR
Source Link
iKlsR
  • 43.7k
  • 12
  • 157
  • 190
Loading