Import Multiple FBX files

Is it possible? What if just modify io_import_multiple_objs.py a little, by simple replace all obj words to fbx, will it work? :confused:

Would be appreciated if someone give me a way to dig in

Found some code, written by McBuff

import bpyimport glob
import os

importDir = “C:\Users\studio\Downloads\ est”
print(importDir)

os.chdir(importDir)
for files in glob.glob(“.obj"):
print( files )
bpy.ops.import_scene.obj(filepath=files, filter_glob="
.obj;*.mtl”, use_ngons=True, use_edges=True, use_smooth_groups=True, use_split_objects=True, use_split_groups=True, use_groups_as_vgroups=False, use_image_search=True, split_mode=‘ON’, global_clamp_size=0, axis_forward=‘-Z’, axis_up=‘Y’)

for files in glob.glob(“.3ds"):
print( files ) bpy.ops.import_scene.autodesk_3ds(filepath=files, filter_glob="
.3ds”, constrain_size=10, use_image_search=True,use_apply_transform=True,axis_forward=‘Y’, axis_up=‘Z’)

and edit it a bit

import bpyimport glob
import os

importDir = “C:\Users\username\Desktop\fbx”
print(importDir)

os.chdir(importDir)
for files in glob.glob(“.fbx"):
print( files )
bpy.ops.import_scene.fbx(filepath=files, filter_glob="
.fbx;*.mtl”, axis_forward=‘-Z’, axis_up=‘Y’)

so it works perfectly! :slight_smile: now I want to place model in grid or row at least, again I would be thankful for some advice

What am I doing wrong here… it can’t seem to find the location of something… I used my username and added fbx folder on my desktop.

File “\Text”, line 1
import bpyimport glob
^
SyntaxError: invalid syntax

location: <unknown location>:-1

Python script fail, look in the console for now…
File “\Text”, line 1
import bpyimport glob
^
SyntaxError: invalid syntax

location: <unknown location>:-1

Python script fail, look in the console for now…

It’s the formatting of the provided script up top… I don’t know enough about python to fix it. :frowning:

Here’s where I’m at so far but it errors on the last line… “indentationError: expected an indented block”

import bpy
import glob
import os

importDir = “C:\Users\ om\Desktop\fbx”
print(importDir)

os.chdir(importDir)

for files in glob.glob(".fbx"):
print( files ) bpy.ops.import_scene.fbx(filepath=files, filter_glob="
.fbx;*.mtl", axis_forward=’-Z’, axis_up=‘Y’)

HA! I got this one to work!!! It came from a facepunch forum post.

import os
import bpy
import glob

put the location to the folder where the FBXs are located here in this fashion

path_to_fbx_dir = os.path.join(‘C:\Users\ om\Desktop\fbx’)

get list of all files in directory

file_list = sorted(os.listdir(path_to_fbx_dir))

get a list of files ending in ‘fbx’

fbx_list = [item for item in file_list if item.endswith(’.fbx’)]

loop through the strings in fbx_list and add the files to the scene

for item in fbx_list:
path_to_file = os.path.join(path_to_fbx_dir, item)
bpy.ops.import_scene.fbx(filepath = path_to_file, filter_glob=".fbx;.mtl", axis_forward=’-Z’, axis_up=‘Y’)

tommywright
For some reason, I haven’t received any notification, but yeah, indentation is a thing :wink:


So finally I do it the right way — github link

It’s defenetly works now, and also there is no need to figuring out the Desktop location manually
(only for Windows users right now)

Decided to push it forward :cool: so now you can import multiple FBX files just as usual with regular Blender menu.
(based on milti-OBJ importer, so special thanks to poor for a plugin that I could edit)

I also rewrote script version slightly, now it contains only three lines of code.

Available on my Github page


I released ealier the FBX Bundle addon which is free and open

https://farm1.staticflickr.com/803/41571646601_25fe40e0a6_o.png

With the specified path the script imports any obj, 3ds or fbx files into the scene

The relevant code snippet


def import_files(path):
	# https://blender.stackexchange.com/questions/5064/how-to-batch-import-wavefront-obj-files
	# http://ricardolovelace.com/batch-import-and-export-obj-files-in-blender.html
	path = bpy.path.abspath(path)


	extensions = ['fbx', 'obj', '3ds']




	filenames = sorted(os.listdir(path))
	filenames_valid = []


	for filename in filenames:
		for ext in extensions:
			if filename.lower().endswith('.{}'.format(ext)):
				filenames_valid.append(filename)
				break




	for name in filenames_valid:
		file_path = os.path.join(path, name)
		extension = (os.path.splitext(file_path)[1])[1:].lower()
		print("- {} = {}".format(extension, file_path))


		# https://docs.blender.org/api/2.78a/bpy.ops.import_scene.html
		if extension == 'fbx':
			if hasattr(bpy.types, bpy.ops.import_scene.fbx.idname()):
				bpy.ops.import_scene.fbx(filepath = file_path)


		elif extension == 'obj':
			if hasattr(bpy.types, bpy.ops.import_scene.obj.idname()):
				bpy.ops.import_scene.obj(filepath = file_path)
				
		elif extension == '3ds':
			if hasattr(bpy.types, bpy.ops.import_scene.autodesk_3ds.idname()):
				bpy.ops.import_scene.autodesk_3ds(filepath = file_path)

Feel free to copy and improve

1 Like