I have the following script (doesn't work) to try to select the next connected vertex (of the current object) in a mesh. Would appreciate some help. thanks

# seems like I need to toggle this to sync script to view. Please help
# if there is a better way!

count = len(bpy.context.scene.objects.active.data.vertices)
  active = [e.index for e in bpy.context.scene.objects.active.data.vertices if e.select][0]
except IndexError:
  active = 0

active = (active+1) % count

for idx, e in enumerate(bpy.context.scene.objects.active.data.vertices):
    if idx==active:
        e.select = True
        e.select = False

enter image description here

  • 2
    $\begingroup$ check out TextEditor -> Templates -> Python -> BMesh Simple EditMode. $\endgroup$
    – zeffii
    Oct 12 '15 at 16:29
  • 1
    $\begingroup$ sweet - that's exactly the kind of help I needed. Posting the working script below. $\endgroup$
    – RoyM
    Oct 12 '15 at 17:14
  • $\begingroup$ modified text above to describe a bit better the intent $\endgroup$
    – RoyM
    Oct 13 '15 at 13:59

You can get all adjacent vertices like this

import bpy
import bmesh

obj = bpy.context.active_object
mesh = obj.data

bm = bmesh.from_edit_mesh(mesh)
active = bm.select_history.active

if active and isinstance(active, bmesh.types.BMVert):
    for edge in active.link_edges:

Based on @zeffii's hint, here's a working script. It selects the first vertex if none selected, and cycles through the list again if needed.

import bpy
import bmesh

# Get the active mesh
obj = bpy.context.edit_object
me = obj.data
bm = bmesh.from_edit_mesh(me)

bm.faces.active = None

count = len(bm.verts)
    activeIndex = [e.index for e in bm.verts if e.select][0]
except IndexError:
    activeIndex = 0
    activeIndex = (activeIndex+1) % count

for idx,v in enumerate(bm.verts):
    v.select = (idx==activeIndex)

# Show the updates in the viewport and recalculate n-gon tessellation.
bmesh.update_edit_mesh(me, True)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.