{"id":48,"date":"2015-10-19T11:25:47","date_gmt":"2015-10-19T11:25:47","guid":{"rendered":"http:\/\/stuff.wp.viranyi.com\/?p=48"},"modified":"2020-01-23T12:51:31","modified_gmt":"2020-01-23T12:51:31","slug":"blender-import-multiple-files","status":"publish","type":"post","link":"http:\/\/stuff.wp.viranyi.com\/?p=48","title":{"rendered":"Blender &#8211; Import multiple files"},"content":{"rendered":"<p>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 &#8230; ). This is for Windows .. but easily adaptable for *nix systems.<\/p>\n<p><strong>How to run?<\/strong><\/p>\n<p>Copy &amp; past the one of the code snippets into Blender&#8217;s Text Editor. Don&#8217;t forget to create a New text file. You&#8217;re not able to paste nor type if there&#8217;s no present.<\/p>\n<p><strong>Objects (OBJ)<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">import os\nimport bpy\n\n# put the location to the folder where the objs are located here in this fashion\n# this line will only work on windows ie C:\\objects\npath_to_obj_dir = os.path.join('C:\\\\', 'objects')\n\n# get list of all files in directory\nfile_list = sorted(os.listdir(path_to_obj_dir))\n\n# get a list of files ending in 'obj'\nobj_list = [item for item in file_list if item.endswith('.obj')]\n\n# loop through the strings in obj_list and add the files to the scene\nfor item in obj_list:\n    path_to_file = os.path.join(path_to_obj_dir, item)\n    bpy.ops.import_scene.obj(filepath = path_to_file)\n    # if heavy importing is expected \n    # you may want use saving to main file after every import \n    bpy.ops.wm.save_mainfile(filepath = \"C:\\\\To\\\\Your\\\\File.blend\")<\/pre>\n<p><strong>Collada (DAE)<\/strong><\/p>\n<p>Importing Collada files differs a little. Object (OBJ) importing is located inside BPY&#8217;s import functionas, Collada&#8217;s is not &#8230;<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">import os\nimport bpy\n\n# put the location to the folder where the objs are located here in this fashion\n# this line will only work on windows ie C:\\objects\npath_to_obj_dir = os.path.join('C:\\\\', 'Some\\\\Folder\\\\Collada\\\\')\n\n# get list of all files in directory\nfile_list = sorted(os.listdir(path_to_obj_dir))\n\n# get a list of files ending in 'dae'\nobj_list = [item for item in file_list if item.endswith('.dae')]\n\n# loop through the strings in obj_list and add the files to the scene\nfor item in obj_list:\n    path_to_file = os.path.join(path_to_obj_dir, item)\n    bpy.ops.wm.collada_import(filepath = path_to_file)\n    # if heavy importing is expected \n    # you may want use saving to main file after every import\n    bpy.ops.wm.save_mainfile(filepath = \"C:\\\\To\\\\Your\\\\File.blend\")<\/pre>\n<p><strong>Filmbox (FBX)<\/strong><\/p>\n<p>Importing FBX files is again, a bit different but the same ..<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">import os\nimport bpy\n\n# put the location to the folder where the FBXs are located here in this fashion\n# this line will only work on windows ie C:\\objects\npath_to_obj_dir = os.path.join('C:\\\\', 'objects')\n\n# get list of all files in directory\nfile_list = sorted(os.listdir(path_to_obj_dir))\n\n# get a list of files ending in 'fbx'\nobj_list = [item for item in file_list if item.endswith('.fbx')]\n\n# loop through the strings in obj_list and add the files to the scene\nfor item in obj_list:\n    path_to_file = os.path.join(path_to_obj_dir, item)\n    bpy.ops.import_scene.fbx(filepath = path_to_file)\n    # if heavy importing is expected \n    # you may want use saving to main file after every import \n    bpy.ops.wm.save_mainfile(filepath = \"C:\\\\To\\\\Your\\\\File.blend\")<\/pre>\n<p><strong>GL Transmission Format (GLB &amp; GLTF)<\/strong><\/p>\n<p>Importing GLB \/ GLTF files is as well inside the import_scene obj, tested with Blender 2.81a:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">import os\nimport bpy\n\n# put the location to the folder where the GLBs are located here in this fashion\n# this line will only work on windows ie C:\\objects\npath_to_obj_dir = os.path.join('C:\\\\', 'objects')\n\n# get list of all files in directory\nfile_list = sorted(os.listdir(path_to_obj_dir))\n\n# get a list of files ending in 'glb' (or 'gltf')\nobj_list = [item for item in file_list if item.endswith('.glb')]\n\n# loop through the strings in obj_list and add the files to the scene\nfor item in obj_list:\n    path_to_file = os.path.join(path_to_obj_dir, item)\n    bpy.ops.import_scene.gltf(filepath = path_to_file)\n    # if heavy importing is expected \n    # you may want use saving to main file after every import \n    bpy.ops.wm.save_mainfile(filepath = \"C:\\\\To\\\\Your\\\\File.blend\")<\/pre>\n<p><strong>Kudos go to ..\u00a0<\/strong><\/p>\n<p>The user <strong>poor<\/strong> has already created importing and exporting scripts including the Blender plugin interface. This needs to be adapted to Collada functions only, et voila.<\/p>\n<p><strong>References<\/strong><\/p>\n<ul>\n<li><a href=\"http:\/\/blender.stackexchange.com\/questions\/5064\/batch-import-wavefront-obj\" target=\"_blank\" rel=\"noopener noreferrer\">StackExchange &#8211; Batch import Wavefront OBJ (incl user poor importer)<\/a><\/li>\n<li><a href=\"http:\/\/stackoverflow.com\/questions\/28992141\/importing-collada-dae-file-into-blender-using-python\" target=\"_blank\" rel=\"noopener noreferrer\">StackOverflow &#8211; Importing Collada files<\/a><\/li>\n<li><a href=\"http:\/\/blender.stackexchange.com\/questions\/5382\/export-multiple-objects-to-obj\/31852#31852\" target=\"_blank\" rel=\"noopener noreferrer\">Export multiple Objects (from user poor)<\/a><\/li>\n<li><a href=\"https:\/\/blender.stackexchange.com\/questions\/65815\/how-do-i-import-a-fbx-file-into-blender-from-command-line\" target=\"_blank\" rel=\"noopener noreferrer\">StackExchange &#8211; How do I import a fbx file into blender from command line?<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>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 &#8230; ). This is for Windows .. but easily adaptable for *nix systems. How to run? Copy &amp; past the one of the code snippets into Blender&#8217;s Text Editor. Don&#8217;t [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-48","post","type-post","status-publish","format-standard","hentry","category-blender"],"_links":{"self":[{"href":"http:\/\/stuff.wp.viranyi.com\/index.php?rest_route=\/wp\/v2\/posts\/48","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/stuff.wp.viranyi.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/stuff.wp.viranyi.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/stuff.wp.viranyi.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/stuff.wp.viranyi.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=48"}],"version-history":[{"count":12,"href":"http:\/\/stuff.wp.viranyi.com\/index.php?rest_route=\/wp\/v2\/posts\/48\/revisions"}],"predecessor-version":[{"id":242,"href":"http:\/\/stuff.wp.viranyi.com\/index.php?rest_route=\/wp\/v2\/posts\/48\/revisions\/242"}],"wp:attachment":[{"href":"http:\/\/stuff.wp.viranyi.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=48"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/stuff.wp.viranyi.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=48"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/stuff.wp.viranyi.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=48"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}