2023-04-11 17:25:35 +02:00
|
|
|
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
|
2023-10-27 17:27:03 +02:00
|
|
|
path_to_obj_dir = os.path.join('/home/phroy/Bureau/seriousgames/blender-edutech/git/climway2-carte/asset/kenney_train-kit/Models/OBJ format')
|
2023-04-11 17:25:35 +02:00
|
|
|
# get list of all files in directory
|
|
|
|
file_list = sorted(os.listdir(path_to_obj_dir))
|
|
|
|
print (file_list)
|
|
|
|
|
|
|
|
|
2023-10-27 17:27:03 +02:00
|
|
|
# get a list of files ending in 'obj'
|
2023-10-27 16:49:21 +02:00
|
|
|
obj_list = [item for item in file_list if item.endswith('.obj')]
|
2023-04-11 17:25:35 +02:00
|
|
|
# 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)
|
2023-10-27 16:49:21 +02:00
|
|
|
print (path_to_file)
|
|
|
|
bpy.ops.wm.obj_import(filepath = path_to_file)
|
2023-04-11 17:25:35 +02:00
|
|
|
# if heavy importing is expected
|
|
|
|
# you may want use saving to main file after every import
|
|
|
|
bpy.ops.wm.save_mainfile(filepath = "/home/phroy/file.blend")
|
|
|
|
|