Blender – Import multiple files

Importing multiple files in Blender is okay-ish. While the underlying API supports that, the higher GUI does not (or was able, but is not anymore … ). This is for Windows .. but easily adaptable for *nix systems.

How to run?

Copy & past the one of the code snippets into Blender’s Text Editor. Don’t forget to create a New text file. You’re not able to paste nor type if there’s no present.

Objects (OBJ)

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)
    # if heavy importing is expected 
    # you may want use saving to main file after every import 
    bpy.ops.wm.save_mainfile(filepath = "C:\\To\\Your\\File.blend")

Collada (DAE)

Importing Collada files differs a little. Object (OBJ) importing is located inside BPY’s import functionas, Collada’s is not …

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:\\', 'Some\\Folder\\Collada\\')

# get list of all files in directory
file_list = sorted(os.listdir(path_to_obj_dir))

# get a list of files ending in 'dae'
obj_list = [item for item in file_list if item.endswith('.dae')]

# 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.wm.collada_import(filepath = path_to_file)
    # if heavy importing is expected 
    # you may want use saving to main file after every import
    bpy.ops.wm.save_mainfile(filepath = "C:\\To\\Your\\File.blend")

Filmbox (FBX)

Importing FBX files is again, a bit different but the same ..

import os
import bpy

# put the location to the folder where the FBXs 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 'fbx'
obj_list = [item for item in file_list if item.endswith('.fbx')]

# 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.fbx(filepath = path_to_file)
    # if heavy importing is expected 
    # you may want use saving to main file after every import 
    bpy.ops.wm.save_mainfile(filepath = "C:\\To\\Your\\File.blend")

GL Transmission Format (GLB & GLTF)

Importing GLB / GLTF files is as well inside the import_scene obj, tested with Blender 2.81a:

import os
import bpy

# put the location to the folder where the GLBs 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 'glb' (or 'gltf')
obj_list = [item for item in file_list if item.endswith('.glb')]

# 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.gltf(filepath = path_to_file)
    # if heavy importing is expected 
    # you may want use saving to main file after every import 
    bpy.ops.wm.save_mainfile(filepath = "C:\\To\\Your\\File.blend")

Kudos go to .. 

The user poor has already created importing and exporting scripts including the Blender plugin interface. This needs to be adapted to Collada functions only, et voila.

References

Leave a Reply

Your email address will not be published. Required fields are marked *