Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import bpy
- base_to_obj_dir = os.path.join('C:\\', 'mypath')
- def reset_blend():
- # simply can be
- # bpy.ops.wm.open_mainfile(filepath=bpy.data.filepath)
- bpy.ops.wm.read_factory_settings()
- for scene in bpy.data.scenes:
- for obj in scene.objects:
- scene.objects.unlink(obj)
- # only worry about data in the startup scene
- for bpy_data_iter in (
- bpy.data.objects,
- bpy.data.meshes,
- bpy.data.lamps,
- bpy.data.cameras,
- ):
- for id_data in bpy_data_iter:
- bpy_data_iter.remove(id_data)
- def main():
- path = os.path.join(base_to_obj_dir, "02828884")
- obj_list = sorted(os.listdir(path))
- # loop through the strings in obj_list and add the files to the scene
- for item in obj_list:
- reset_blend()
- source_to_file = os.path.join(path, item, "model.obj")
- target_to_file = os.path.join(path, item, "model_r.obj")
- bpy.ops.import_scene.obj(filepath=source_to_file)
- bpy.ops.import_scene.obj(filepath=source_to_file)
- obj_objects = bpy.context.selected_objects[:]
- #obj_objects = [ o for o in bpy.context.scene.objects if o.select ]
- print("Starting--------------------------------------------")
- for obj in obj_objects:
- bpy.ops.object.select_all(action='DESELECT')
- obj.select = True
- bpy.context.scene.objects.active = obj
- # go edit mode
- bpy.ops.object.mode_set(mode='EDIT')
- # select al faces
- bpy.ops.mesh.select_all(action='SELECT')
- # recalculate outside normals
- bpy.ops.mesh.normals_make_consistent(inside=False)
- # go object mode again
- bpy.ops.object.editmode_toggle()
- print("Ending--------------------------------------------")
- bpy.ops.export_scene.obj(filepath=target_to_file,use_materials=True)
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement