Is it possible to batch import Wavefront .obj to blender? I'm working on 2.69. If I select multiple .obj files, only one gets imported. Also if I hit A on file selection window to select all files (.obj and .mtl) I get an error, nothing gets imported. I have to import several hundreds of .obj into the blender file, is this possible?
2 Answers
The following Add-on allows to import multiple Wavefront OBJ files at once. By using the file browser the import process is platform independent. Also all the usual options like Forward Axis, Up Axis or Clamp Size are available.
Repository: github.com/p2or/blender-batch-import-wavefront-obj
io_batch_import_objs.py (updated for 3.5+)
# ##### BEGIN GPL LICENSE BLOCK #####
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####
# <pep8 compliant>
bl_info = {
"name": "Batch Import Wavefront (.obj)",
"author": "p2or",
"version": (0, 7, 0),
"blender": (3, 5, 0),
"location": "File > Import-Export",
"description": "Import multiple OBJ files, UV's and their materials",
"doc_url": "https://github.com/p2or/blender-batch-import-wavefront-obj",
"tracker_url": "https://github.com/p2or/blender-batch-import-wavefront-obj",
"category": "Import-Export"}
import bpy
from pathlib import Path
from bpy_extras.io_utils import ImportHelper
from bpy.props import (BoolProperty,
FloatProperty,
StringProperty,
EnumProperty,
CollectionProperty)
class WM_OT_batchWavefront(bpy.types.Operator, ImportHelper):
"""Batch Import Wavefront"""
bl_idname = "wm.obj_import_batch"
bl_label = "Import multiple OBJ's"
bl_options = {'PRESET', 'UNDO'}
filename_ext = ".obj"
filter_glob = StringProperty(
default="*.obj",
options={'HIDDEN'})
files: CollectionProperty(type=bpy.types.PropertyGroup)
global_scale_setting: FloatProperty(
name="Scale",
description="Value by which to enlarge or shrink" \
"the objects with respect to the world origin",
min=0.0001, max=10000.0,
soft_min=0.01, soft_max=1000.0,
default=1.0)
clamp_size_setting: FloatProperty(
name="Clamp Bounding Box",
description="Resize the objects to keep bounding box" \
"under this value. Value 0 diables clamping",
min=0.0, max=1000.0,
soft_min=0.0, soft_max=1000.0,
default=0.0)
axis_forward_setting: EnumProperty(
name="Forward Axis",
items=(('X', "X", ""),
('Y', "Y", ""),
('Z', "Z", ""),
('NEGATIVE_X', "-X", ""),
('NEGATIVE_Y', "-Y", ""),
('NEGATIVE_Z', "-Z", ""),
),
default='NEGATIVE_Z')
axis_up_setting: EnumProperty(
name="Up Axis",
items=(('X', "X", ""),
('Y', "Y", ""),
('Z', "Z", ""),
('NEGATIVE_X', "-X", ""),
('NEGATIVE_Y', "-Y", ""),
('NEGATIVE_Z', "-Z", ""),
),
default='Y')
validate_setting: BoolProperty(
name="Validate Meshes",
description="Check imported mesh objects for invalid data")
vgroup_setting: BoolProperty(
name="Vertex Groups",
description="Import OBJ groups as vertex groups")
use_split_objects_setting: BoolProperty(
name="Split By Object",
default=True,
description="Import each OBJ 'o' as a separate object")
use_split_groups_setting: BoolProperty(
name="Split By Group",
description="Import each OBJ 'o' as a separate object")
def draw(self, context):
layout = self.layout
layout.use_property_split = True
layout.use_property_decorate = False # No animation.
box = layout.box()
box.label(text="Transform", icon='OBJECT_DATA')
col = box.column()
col.prop(self, "global_scale_setting")
col.prop(self, "clamp_size_setting")
col.separator()
col.row().prop(self, "axis_forward_setting", expand=True)
col.separator(factor=0.5)
col.row().prop(self, "axis_up_setting", expand=True)
col.separator()
box = layout.box()
box.label(text="Options", icon='EXPORT')
col = box.column()
col.prop(self, "use_split_objects_setting")
col.prop(self, "use_split_groups_setting")
col.prop(self, "vgroup_setting")
col.prop(self, "validate_setting")
def execute(self, context):
folder = Path(self.filepath)
for selection in self.files:
fp = Path(folder.parent, selection.name)
if fp.suffix == '.obj':
bpy.ops.wm.obj_import(
filepath = str(fp),
global_scale = self.global_scale_setting,
clamp_size = self.clamp_size_setting,
forward_axis = self.axis_forward_setting,
up_axis = self.axis_up_setting,
use_split_objects = self.use_split_objects_setting,
use_split_groups = self.use_split_groups_setting,
import_vertex_groups = self.vgroup_setting,
validate_meshes = self.validate_setting
)
return {'FINISHED'}
def menu_func_import(self, context):
self.layout.operator(
WM_OT_batchWavefront.bl_idname,
text="Wavefront Batch (.obj)")
def register():
bpy.utils.register_class(WM_OT_batchWavefront)
bpy.types.TOPBAR_MT_file_import.append(menu_func_import)
def unregister():
bpy.utils.unregister_class(WM_OT_batchWavefront)
bpy.types.TOPBAR_MT_file_import.remove(menu_func_import)
if name == "main":
register()
# test call
#bpy.ops.wm.obj_import_batch('INVOKE_DEFAULT')
Note: It is basically just a quick and dirty wrapper of wm.obj_import or import_scene.obj operator in versions prior to Blender 3.2.0 until batch import is supported. To batch export scene objects, see: Export multiple objects to .obj?
Versions
To keep track of all the changes over the years I decided to create a dedicated repository instead of posting each version here, which makes it easier to download as well:
| Blender | Addon Version | Release |
|---|---|---|
| Blender 2.65+ | 0.1.0 | Download |
| Blender 2.80+ | 0.2.0 | Download |
| Blender 2.92+ | 0.3.0 | Download |
| Blender 3.2+ | 0.4.0 | Download |
| Blender 3.3+ | 0.5.0 | Download |
| Blender 3.4+ | 0.6.1 | Download |
| Blender 3.5+ | 0.7.0 | Download |
@JuhaW added a Scale setting to 0.2.0, you can download the latest version from here.
- 15,860
- 10
- 83
- 143
Unfortunately, this is not possible by default with Blender 2.5x+ it seems. In 2.49, you could hold Shift then press the Import Obj button and it would prompt you to select a directory with the sequence.
In 2.69 - and at least until 2.82 - you can do the same with a script — it could be converted into a more usable utility but it works.
import os
import bpy
put the location to the folder where the objs are located here in this fashion
this line will only work on windows ie C:\objects
path_to_obj_dir = os.path.join('C:\', 'objects')
get list of all files in directory
file_list = sorted(os.listdir(path_to_obj_dir))
get a list of files ending in 'obj'
obj_list = [item for item in file_list if item.endswith('.obj')]
loop through the strings in obj_list and add the files to the scene
for item in obj_list:
path_to_file = os.path.join(path_to_obj_dir, item)
bpy.ops.import_scene.obj(filepath = path_to_file, use_split_objects=False, use_split_groups=False)
For unix machines the direct path should look like:
# location of obj folder
path_to_obj_dir = '/home/user/Desktop/objects/'
-
2To use the script, simply paste it into Blender's text editor, edit the path on the 5th line and press
Alt + Por Run. – iKlsR Nov 23 '13 at 16:09 -
Thank you so much, works like a charm, but I had to do some research and trial error with my very poor knowledge of python. I had to change the extension to OBJ because by using print(obj_list) I noticed that it wasn't seeing the objs that had an uppercase extension, checked it with print(file_list) and then changed to OBJ and it worked! – finsopraiets Nov 24 '13 at 19:22
-
@akzash rejected your suggested edit re removing objects from windwos path. Your error would be in that you don't have an objects folder in c drive. – batFINGER Dec 14 '17 at 12:22
-
@iKlsR I am importing many
.objfiles sequentially. Very quickly, import time increases significantly to the point that it takes minutes for each object to get imported. Could you please take a look at my question here and see if you can offer a solution? Appreciate it. – Amir Mar 04 '18 at 20:38 -
1FWIW the same
bpy.ops.import_scene.obj()method will also work in Blender 2.82. – ComputerScientist Jun 03 '20 at 15:08

context.selected_objects[0]. For demonstration purposes I added a parent property to the interface: https://gist.github.com/p2or/d4956ed05af4618fab0b7f931c50f990. If it's enabled it will create an empty as parent for all imported objects automatically. I hope this is what you want @RayKoopa, right? – p2or Jul 15 '16 at 15:11print(obj_list)afterbpy.ops.import_scene.objin the Add-on and you'll see that this will work – p2or Jul 15 '16 at 16:15