Blender 2.6: “remove doubles” for all objects

One of those “Google-holes”: you’re searching for something – and find nothing. So let’s fix this (and for me, it’s where I can find it again, kind of a web-clipboard).

Here’s the problem: Working with Blender, I imported a 3D scene from another program. After a few clicks, I realize that all vertices are duplicated (Collada import, and no way to change the export settings). Select, toggle edit mode, “remove doubles”, “recalculate normals” would be a valid approach for 10 meshes. But suppose you end up with several 100s? Right, there’s Blender’s built-in Python interpreter. So fire it up an any Blender window you like using the little button on the bottom left:

…and paste the following into that window (you might have to add one press of the return key). The script only works on the selected meshes (and ignores non-meshes), which makes it easier for really huge scenes – you might want to select only a few of them to get started, because Blender will be inresponsive during the script doing its job:

import bpy
if bpy.context.selected_objects != []:
	for ob in bpy.context.selected_objects:
		if ob.type == 'MESH':
			bpy.context.scene.objects.active = ob 
			bpy.ops.object.mode_set(mode='EDIT') 
			bpy.ops.mesh.select_all() 
			# remove doubles:
			bpy.ops.mesh.remove_doubles() 
			# recalculate outside normals:
			bpy.ops.mesh.normals_make_consistent(inside=False)
			bpy.ops.object.mode_set(mode='OBJECT')

 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.