acoolrocket

Blender - Delete duplicate meshes with same tris count

Sep 11th, 2025
14
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. import bpy
  2. import bmesh
  3.  
  4. def get_tri_count(obj):
  5. """Return the exact triangle count of a mesh object."""
  6. if obj.type != 'MESH':
  7. return None
  8. # Create a temporary bmesh to calculate triangulated face count
  9. mesh = obj.data
  10. bm = bmesh.new()
  11. bm.from_mesh(mesh)
  12. bmesh.ops.triangulate(bm, faces=bm.faces[:])
  13. tri_count = len(bm.faces)
  14. bm.free()
  15. return tri_count
  16.  
  17. def delete_duplicate_meshes():
  18. seen = {}
  19. to_delete = []
  20.  
  21. for obj in bpy.context.scene.objects:
  22. if obj.type == 'MESH':
  23. tri_count = get_tri_count(obj)
  24. if tri_count is None:
  25. continue
  26.  
  27. # If this tri_count already exists, mark duplicates for deletion
  28. if tri_count in seen:
  29. print(f"Duplicate found: {obj.name} (tris={tri_count}) -> deleting")
  30. to_delete.append(obj)
  31. else:
  32. seen[tri_count] = obj
  33.  
  34. # Delete duplicates
  35. bpy.ops.object.select_all(action='DESELECT')
  36. for obj in to_delete:
  37. obj.select_set(True)
  38. bpy.ops.object.delete()
  39.  
  40. delete_duplicate_meshes()
Advertisement
Add Comment
Please, Sign In to add comment