Results 1 to 9 of 9
  1. #1
    Member chombor's Avatar
    Join Date
    Mar 2016
    Location
    Russian Federation
    Posts
    46

    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?

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



  2. #2
    Member chombor's Avatar
    Join Date
    Mar 2016
    Location
    Russian Federation
    Posts
    46
    Found some code, written by McBuff

    import bpyimport glob
    import os

    importDir = "C:\\Users\\studio\\Downloads\\test"
    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,axi s_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! ^_^ now I want to place model in grid or row at least, again I would be thankful for some advice



  3. #3
    Member tommywright's Avatar
    Join Date
    Mar 2011
    Location
    Cary, NC
    Posts
    705
    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...
    Last edited by tommywright; 24-Feb-18 at 11:32.



  4. #4
    Member tommywright's Avatar
    Join Date
    Mar 2011
    Location
    Cary, NC
    Posts
    705
    It's the formatting of the provided script up top... I don't know enough about python to fix it.



  5. #5
    Member tommywright's Avatar
    Join Date
    Mar 2011
    Location
    Cary, NC
    Posts
    705
    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\\tom\\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')



  6. #6
    Member tommywright's Avatar
    Join Date
    Mar 2011
    Location
    Cary, NC
    Posts
    705
    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\\tom\\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')



  7. #7
    Member chombor's Avatar
    Join Date
    Mar 2016
    Location
    Russian Federation
    Posts
    46
    tommywright
    For some reason, I haven't received any notification, but yeah, indentation is a thing

    Code_2018-04-09_03-37-09.jpg


    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)



  8. #8
    Member chombor's Avatar
    Join Date
    Mar 2016
    Location
    Russian Federation
    Posts
    46
    Decided to push it forward 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

    blender_2018-04-11_04-20-07.jpg



  9. #9
    Member renderhjs's Avatar
    Join Date
    Aug 2017
    Location
    Sydney, Australia
    Posts
    98
    I released ealier the FBX Bundle addon which is free and open
    https://blenderartists.org/forum/sho...720-FBX-Bundle



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

    The relevant code snippet
    Code:
    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
    Game Developer & Tech Artist. TexTools Blender | FBX Bundle export addon | Portfolio | twitter | YouTube



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •