Importing A Directory Full of Obj Files Into Blender

 

I was recently working with a tool that exported it’s level data as a directory full of obj files, literally hundreds of them.  You can import them into Blender using File->Import->Obj, unfortunately there is no way to do a select all.  Apparently in Blender 2.4x if you held SHIFT while selecting OBJ import, it would import an entire directory, but this doesn’t appear to work in modern Blender.  You can also SHIFT+Click multiple files to do multiple selection, but this gets tedious when you have hundreds of them.  Unfortunately CTRL + A doesn’t work…

 

Thankfully Blender is extremely scriptable, so let’s turn to Python for a solution.  The following script will import a directory full of OBJ files into the current scene.

import bpy  import os    def fileList(path):       for dirpath, dirnames, filenames in os.walk(path):          for filename in filenames:              yield os.path.join(dirpath, filename)    for f in fileList("C:\file\path\here\"):      if f.lower().endswith(".obj"):          bpy.ops.import_scene.obj(f)  

Be sure to change the path to your directory and if on Mac OS or Linux, to change the path format /to/this/style. Otherwise this script will chug away importing the OBJ files for you. Hopefully at some point Blender gives you the ability to select all while importing and the need for this script goes away completely.

Art Programming


Scroll to Top