I have about 20 files I need to import into blender but each one is big so takes a while. I tried holding shift while selecting the OBJ files in the import browser window, but it only loads in the last one selected?
Here’s a simple script to help you get obj’s and 3ds files imported from a chosen directory.
Now I have been lazy so you’ll have to do 2 things to get this to work.
-
Put all your obj’s and 3d’s files into a single folder with NOTHING ELSE IN IT
-
Open a script panel in blender and paste the code below in it.
Copy the folderpath you have chosen for your models. Go to the script and replace everything between the “” on the line with importDir with your copied folder path. Also add additional \ for every \ in the path.
So you should end up with: importDir=“C:\somefolder\somefolder”
once you’re done, press the Run Script button.
If the info panel displays an error, then I’m sorry to inform you that you’re boned.
If not, just wait until all of your models are there.
import bpy
import 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')
Wow i was hoping there’d be an easy switch/toggle somewhere (i am lazy). If i have to do programming to make it work i’ll just do them one at a time, I’m usually only working with projects that require 20 imports or less so no real biggy.
One thing that is mistifying me at the moment though is blender’s memory usage. I open a 30-40Mb model and suddenly blender is using about 500mb of ram. Why does it need so much? I note there seems to be some importing memory issues as if i save after importing and reopen the scene, the memory usage decreases noticably.
I have just imported 18 OBJ files and blender was using about 11-12gb of ram, I SAVED the scene, quit blender and reopened the file and its now using 3.8gb of ram. Can someone offer any general advice on this?
Not on that specific matter no, but I have noticed that many imported objects have every face detached from eachother which is very annoying and not really workable, and secondly it’s very memory intense.
Just imagine that a single quad (4 verts) would become 2 tris with each 3 vertices. That’s 50% extra data for no reason.
I always have to remove double and such to fix this, and then again chances are that you get errors in your mesh that’ll screw up your normals.
Now on the matter of importing multiple objects, I kinda just gave you the code because I have a script that imports models and saves blend files seperatly for each model. I just recycled what I had there to give you something that should work.
It’s odd that your importing of multiple models is failing, because normally it does work like you described.
What happened to the ‘import-multiple-objects’ addon?
It used to work perfectly fine.
In case of need, there are two solutions:
1:use this addon with the 2.8 version:
# ##### BEGIN GPL LICENSE BLOCK #####
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####
# <pep8 compliant>
bl_info = {
"name": "Import multiple OBJ files",
"author": "poor, JuhaW, Alexander Belyakov",
"version": (0, 3, 0),
"blender": (2, 80, 0),
"location": "File > Import-Export",
"description": "Import multiple OBJ files, UV's, materials",
"warning": "",
"wiki_url": "",
"tracker_url": "",
"category": "Import-Export"}
import bpy
import os
from bpy_extras.io_utils import ImportHelper
from bpy.props import (BoolProperty,
FloatProperty,
StringProperty,
EnumProperty,
CollectionProperty
)
class ImportMultipleObjs(bpy.types.Operator, ImportHelper):
"""This appears in the tooltip of the operator and in the generated docs"""
bl_idname = "import_scene.multiple_objs"
bl_label = "Import multiple OBJ's"
bl_options = {'PRESET', 'UNDO'}
# ImportHelper mixin class uses this
filename_ext = ".obj"
filter_glob: StringProperty(
default="*.obj",
options={'HIDDEN'},
)
# Selected files
files: CollectionProperty(type=bpy.types.PropertyGroup)
# List of operator properties, the attributes will be assigned
# to the class instance from the operator settings before calling.
edges_setting: BoolProperty(
name="Lines",
description="Import lines and faces with 2 verts as edge",
default=True,
)
smooth_groups_setting: BoolProperty(
name="Smooth Groups",
description="Surround smooth groups by sharp edges",
default=True,
)
split_objects_setting: BoolProperty(
name="Object",
description="Import OBJ Objects into Blender Objects",
default=True,
)
split_groups_setting: BoolProperty(
name="Group",
description="Import OBJ Groups into Blender Objects",
default=True,
)
groups_as_vgroups_setting: BoolProperty(
name="Poly Groups",
description="Import OBJ groups as vertex groups",
default=False,
)
image_search_setting: BoolProperty(
name="Image Search",
description="Search subdirs for any associated images "
"(Warning, may be slow)",
default=False
)
split_mode_setting: EnumProperty(
name="Split",
items=(('ON', "Split", "Split geometry, omits unused verts"),
('OFF', "Keep Vert Order", "Keep vertex order from file"),),
)
clamp_size_setting: FloatProperty(
name="Clamp Size",
description="Clamp bounds under this value (zero to disable)",
min=0.0, max=1000.0,
soft_min=0.0, soft_max=1000.0,
default=0.0,
)
axis_forward_setting: EnumProperty(
name="Forward",
items=(('X', "X Forward", ""),
('Y', "Y Forward", ""),
('Z', "Z Forward", ""),
('-X', "-X Forward", ""),
('-Y', "-Y Forward", ""),
('-Z', "-Z Forward", ""),
),
default='-Z',
)
axis_up_setting: EnumProperty(
name="Up",
items=(('X', "X Up", ""),
('Y', "Y Up", ""),
('Z', "Z Up", ""),
('-X', "-X Up", ""),
('-Y', "-Y Up", ""),
('-Z', "-Z Up", ""),
),
default='Y',
)
scale_setting: FloatProperty(
name="Size",
description="Scale objects",
min=0.0, max=1000.0,
soft_min=0.0, soft_max=1000.0,
default=1,
)
center_origin: BoolProperty(
name="Center Origin",
default=True
)
def draw(self, context):
layout = self.layout
row = layout.row(align=True)
row.prop(self, "smooth_groups_setting")
row.prop(self, "edges_setting")
box = layout.box()
row = box.row()
row.prop(self, "split_mode_setting", expand=True)
row = box.row()
if self.split_mode_setting == 'ON':
row.label(text="Split by:")
row.prop(self, "split_objects_setting")
row.prop(self, "split_groups_setting")
else:
row.prop(self, "groups_as_vgroups_setting")
row = layout.split()
row.prop(self, "clamp_size_setting")
layout.prop(self, "axis_forward_setting")
layout.prop(self, "axis_up_setting")
layout.prop(self, "image_search_setting")
row = layout.split()
row.prop(self, "scale_setting")
row.prop(self, "center_origin")
def execute(self, context):
# get the folder
folder = (os.path.dirname(self.filepath))
# iterate through the selected files
for j, i in enumerate(self.files):
# generate full path to file
path_to_file = (os.path.join(folder, i.name))
# call obj operator and assign ui values
bpy.ops.import_scene.obj(filepath=path_to_file,
axis_forward=self.axis_forward_setting,
axis_up=self.axis_up_setting,
use_edges=self.edges_setting,
use_smooth_groups=self.smooth_groups_setting,
use_split_objects=self.split_objects_setting,
use_split_groups=self.split_groups_setting,
use_groups_as_vgroups=self.groups_as_vgroups_setting,
use_image_search=self.image_search_setting,
split_mode=self.split_mode_setting,
global_clight_size=self.clamp_size_setting)
if self.center_origin:
bpy.ops.object.origin_set(type='ORIGIN_GEOMETRY', center='BOUNDS')
bpy.ops.transform.resize(value=(self.scale_setting, self.scale_setting, self.scale_setting), constraint_axis=(False, False, False))
bpy.ops.object.transform_apply(location=False, rotation=False, scale=True)
return {'FINISHED'}
# Only needed if you want to add into a dynamic menu
def menu_func_import(self, context):
self.layout.operator(ImportMultipleObjs.bl_idname, text="Import multiple (.obj)")
def register():
bpy.utils.register_class(ImportMultipleObjs)
bpy.types.TOPBAR_MT_file_import.append(menu_func_import)
def unregister():
bpy.utils.unregister_class(ImportMultipleObjs)
bpy.types.TOPBAR_MT_file_import.remove(menu_func_import)
if __name__ == "__main__":
register()
2:Run this one in the text editor from version 2.92:
# ##### BEGIN GPL LICENSE BLOCK #####
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####
# <pep8 compliant>
bl_info = {
"name": "Batch Import Wavefront (.obj)",
"author": "p2or",
"version": (0, 1, 0),
"blender": (2, 92, 0),
"location": "File > Import-Export",
"description": "Import multiple OBJ files, UV's, materials",
"warning": "",
"wiki_url": "",
"tracker_url": "",
"category": "Import-Export"}
import bpy
import os
from bpy_extras.io_utils import ImportHelper
from bpy.props import (BoolProperty,
FloatProperty,
StringProperty,
EnumProperty,
CollectionProperty
)
class ImportMultipleObjs(bpy.types.Operator, ImportHelper):
"""Batch Import Wavefront obj"""
bl_idname = "import_scene.multiple_objs"
bl_label = "Import multiple OBJ's"
bl_options = {'PRESET', 'UNDO'}
# ImportHelper mixin class uses this
filename_ext = ".obj"
filter_glob = StringProperty(
default="*.obj",
options={'HIDDEN'},
)
# Selected files
files: CollectionProperty(type=bpy.types.PropertyGroup)
# List of operator properties, the attributes will be assigned
# to the class instance from the operator settings before calling.
edges_setting: BoolProperty(
name="Lines",
description="Import lines and faces with 2 verts as edge",
default=True,
)
smooth_groups_setting: BoolProperty(
name="Smooth Groups",
description="Surround smooth groups by sharp edges",
default=True,
)
split_objects_setting: BoolProperty(
name="Object",
description="Import OBJ Objects into Blender Objects",
default=True,
)
split_groups_setting: BoolProperty(
name="Group",
description="Import OBJ Groups into Blender Objects",
default=True,
)
groups_as_vgroups_setting: BoolProperty(
name="Poly Groups",
description="Import OBJ groups as vertex groups",
default=False,
)
image_search_setting: BoolProperty(
name="Image Search",
description="Search subdirs for any associated images "
"(Warning, may be slow)",
default=True,
)
split_mode_setting: EnumProperty(
name="Split",
items=(('ON', "Split", "Split geometry, omits unused verts"),
('OFF', "Keep Vert Order", "Keep vertex order from file"),
),
)
clamp_size_setting: FloatProperty(
name="Clamp Size",
description="Clamp bounds under this value (zero to disable)",
min=0.0, max=1000.0,
soft_min=0.0, soft_max=1000.0,
default=0.0,
)
axis_forward_setting: EnumProperty(
name="Forward",
items=(('X', "X Forward", ""),
('Y', "Y Forward", ""),
('Z', "Z Forward", ""),
('-X', "-X Forward", ""),
('-Y', "-Y Forward", ""),
('-Z', "-Z Forward", ""),
),
default='-Z',
)
axis_up_setting: EnumProperty(
name="Up",
items=(('X', "X Up", ""),
('Y', "Y Up", ""),
('Z', "Z Up", ""),
('-X', "-X Up", ""),
('-Y', "-Y Up", ""),
('-Z', "-Z Up", ""),
),
default='Y',
)
def draw(self, context):
layout = self.layout
row = layout.row(align=True)
row.prop(self, "smooth_groups_setting")
row.prop(self, "edges_setting")
box = layout.box()
row = box.row()
row.prop(self, "split_mode_setting", expand=True)
row = box.row()
if self.split_mode_setting == 'ON':
row.label(text="Split by:")
row.prop(self, "split_objects_setting")
row.prop(self, "split_groups_setting")
else:
row.prop(self, "groups_as_vgroups_setting")
row = layout.split(factor=0.67)
row.prop(self, "clamp_size_setting")
layout.prop(self, "axis_forward_setting")
layout.prop(self, "axis_up_setting")
layout.prop(self, "image_search_setting")
def execute(self, context):
# get the folder
folder = (os.path.dirname(self.filepath))
# iterate through the selected files
for i in self.files:
# generate full path to file
path_to_file = (os.path.join(folder, i.name))
# call obj operator and assign ui values
bpy.ops.import_scene.obj(
filepath = path_to_file,
axis_forward = self.axis_forward_setting,
axis_up = self.axis_up_setting,
use_edges = self.edges_setting,
use_smooth_groups = self.smooth_groups_setting,
use_split_objects = self.split_objects_setting,
use_split_groups = self.split_groups_setting,
use_groups_as_vgroups = self.groups_as_vgroups_setting,
use_image_search = self.image_search_setting,
split_mode = self.split_mode_setting,
global_clamp_size = self.clamp_size_setting)
return {'FINISHED'}
# Only needed if you want to add into a dynamic menu
def menu_func_import(self, context):
self.layout.operator(ImportMultipleObjs.bl_idname, text="Wavefront Batch (.obj)")
def register():
bpy.utils.register_class(ImportMultipleObjs)
bpy.types.TOPBAR_MT_file_import.append(menu_func_import)
def unregister():
bpy.utils.unregister_class(ImportMultipleObjs)
bpy.types.TOPBAR_MT_file_import.remove(menu_func_import)
if __name__ == "__main__":
register()
# test call
#bpy.ops.import_scene.multiple_objs('INVOKE_DEFAULT')
None of these methods keep the names, which would be helpful.
Updated for 2.92…
? I already shared the updated version; and one of yours goes about the fbx.
The page list both the OBJ and the FBX they are from the same creator…
thanks a lot for this! dont get why blender doesnt let you do that in the first place.