1
$\begingroup$

How to select vertices nearest to each selected vertex (which share the same edges) by specific distance? For example: enter image description here

$\endgroup$
0

1 Answer 1

7
$\begingroup$

I have seen the nice example (which is has been deleted by author), where you can find the nearest vertexes using fast and effective KDTree search.

https://docs.blender.org/api/current/mathutils.kdtree.html

import mathutils
import bmesh

from bpy import context
obj = context.object

# create a kd-tree from a mesh
mesh = bmesh.from_edit_mesh(obj.data)
size = len(mesh.verts)
kd = mathutils.kdtree.KDTree(size)

for i, v in enumerate(mesh.verts):
    kd.insert(v.co, i)

kd.balance()

# Find points within a radius
print("Close points within 0.5 distance")
for v in [v for v in mesh.verts if v.select]:
    co_find = v.co
    for (co, index, dist) in kd.find_range(co_find, 0.5):
        mesh.verts[index].select = True
        print("    ", co, index, dist)
        
bmesh.update_edit_mesh(obj.data)

But to make sure that they are connected, you have to look at edges array of bmesh (something like this):

 for e in mesh.edges:
     if (e.verts[0]==v and e.verts[1].index == index) or (e.verts[1]==v and e.verts[0].index == index) :
         mesh.verts[index].select = True
         print("    ", co, index, dist)
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .