# Python automation, normals, and dupliverts

I'm working with some huge STL models broken into multiple meshes. To automate mesh refining, I'm using this code:

import bpy

scene = bpy.context.scene
selected = bpy.context.selected_objects

for obj in selected:
scene.objects.active = obj
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.remove_doubles()
bpy.ops.mesh.normals_make_consistent()
bpy.ops.object.mode_set(mode='OBJECT')


It takes a significant amount of time to process. Am I doing this right, or is there a quicker way, perhaps with bpy.data?

The equivalent using BMesh and bmesh.ops would be:

import bpy
import bmesh

for obj in bpy.context.selected_objects:

bm = bmesh.new()   # create an empty BMesh
bm.from_mesh(obj.data)   # fill it in from a Mesh

d = 0.0001
bm_verts = bm.verts[:]
bmesh.ops.remove_doubles(bm, verts=bm_verts, dist=d)

bm_faces = bm.faces[:]
bmesh.ops.recalc_face_normals(bm, faces=bm_faces)

bm.to_mesh(obj.data)
bm.free()


But, i doubt it will be much faster.

• bmesh is much faster ( ~ 20x as fast ). Perhaps something wrong with my build. – Bartłomiej Szczepaniak Feb 21 '15 at 17:50
• cool. I wonder how many objects you are doing this to? – zeffii Feb 21 '15 at 20:14