# How do I import multiple OBJ files into blender using python? [duplicate]

So far I have the code:

scene = bpy.context.scene
import_avHat1 = bpy.ops.import_scene.obj(filepath=avatarHat_1)
import_avHat2 = bpy.ops.import_scene.obj(filepath=avatarHat_2)
import_avHat3 = bpy.ops.import_scene.obj(filepath=avatarHat_3)
hats = bpy.context.selected_objects[:]

for obj in hats:
# print the name of the current obj
print (obj.name)
bpy.context.view_layer.objects.active = obj

obj_camera = bpy.context.scene.camera
scene.render.image_settings.file_format = 'PNG'
scene.render.filepath = "~/mark/renderOutput.png"
bpy.ops.render.render(write_still = 1)


It only renders the first hat and I get no errors importing the others. What should I do? This occurs in blender 2.8.

• what if you execute the code line by line in the Python console. Do the import_avHatn variables have the correct meshes? – rob Aug 20 '19 at 18:51
• I've done that and they do. – Steven Newhouse Aug 20 '19 at 18:54
• Oh nevermind they don't have the correct meshes. If you post that as an answer I'll mark it. – Steven Newhouse Aug 20 '19 at 18:59
• lol somebody upvoted my question. it works! i'm just an idiot. – Steven Newhouse Aug 20 '19 at 19:00