Blender script to round vertices positions
Here is a little Blender Python script to round vertices positions from something like 1.0001
to 1.0
.
It operates only on the verts you have selected while in Edit mode. If you want it to run on all verts then comment out lines 7 and 8.
import bpy, bmesh
from mathutils import Vector
bm = bmesh.from_edit_mesh(bpy.context.edit_object.data)
for v in bm.verts:
if not v.select:
continue
for part in range(3):
rounded = round(v.co[part])
diffFromZero = v.co[part] - rounded
if (diffFromZero > 0 and diffFromZero < 0.1) or (diffFromZero < 0 and diffFromZero > -0.1):
print(f"Before: {v.co}")
posMove = Vector((0,0,0))
posMove[part] = diffFromZero * -1
bmesh.ops.translate(bm, verts=[v], vec=posMove)
print(f"After: {v.co}")
bm.normal_update()
bmesh.update_edit_mesh(bpy.context.edit_object.data)
Enjoy!