# Selecting other vertices connected to a selected vertex of a mesh object

As shown in the figure, I want to select the vertices that are connected to a selected vertice. In the left side of the figure, you can see a vertex of a cube is selected. My task is to select the circled vertices as shown in the right side of the figure.

I've tried "Ctrl+numpad+" (Grow selection), that gives me incorrect results as seen in the right figure, it selects some other vertices too (marked as question marks). Please advice me a way of doing the same and preferably in python script as I need to do this for a whole lot of objects.

What you're looking for is the 'select_more' operator under bpy.ops.mesh:

bpy.ops.mesh.select_more(use_face_step = False)


We're using the use_face_step = False parameter, to ensure it only selects linked vertices, not linked vertices via linked faces.

If you don't want to use operators, you can also use bmesh in a slightly longer script:

import bpy, bmesh

# Assuming active object in edit mode (for bmesh.from_edit_mesh)
mesh = bpy.context.object.data
bm = bmesh.from_edit_mesh(mesh)

# Get active vertex (assuming there is only 1 selected)
last = bm.select_history[-1] # history.active doesn't exist anymore...
# and last is a list, of one element

# Select all connected edges
for e in last.link_edges: e.select = True

bm.select_flush(True) # will update face selection

# this line is needed to close bmesh and see the result of the selection
bmesh.update_edit_mesh(mesh)

• Thank you again. I tried visiting all the edges one by one to check if a vertex is selected. If a vertex is selected, I selected the other vertex and vice versa. I'll compare the results from that with these ones. I used this script: for k in range (0, len(obj.data.edges)): A = (bpy.data.meshes['mesh3606'].edges[k].vertices[0]) B = (bpy.data.meshes['mesh3606'].edges[k].vertices[1]) if obj.data.vertices[A].select == True: obj.data.vertices[B].select = True if obj.data.vertices[B].select == True: obj.data.vertices[A].select = True Jun 28 '17 at 8:42
• bpy.ops.mesh.select_more(use_face_step = False) seems to be more correct that the visiting each edge (the method I mentioned previously). Thanks a lot. cheers! Jun 28 '17 at 8:55
• No problem @Debaditya. The bmesh approach will also work, operators are usually considered to be slower than low level operations, which is why I specified the 2nd approach as well. In this case, however, if you're not worried about performance, the simplicity of the 1 line operator is a big advantage for code maintainability, in my opinion. Jun 28 '17 at 9:10
• @TLousky why not use for e in v.link_edges: e.select = True ? Also maybe bm.select_history.active could be used to get active vert. Jun 28 '17 at 9:15
• @batFINGER, good suggestions. Will amend code. Jun 28 '17 at 9:17

The Select More (and Select Less) includes an option in the Tool Shelf (T) for Face Step which is enabled by default.

When enabled the section is grown (or shrunk) by faces rather than edges. Unchecking the Face Step checkbox changes the behavior to grow (or shrink) based on only edges.

• Thank you so much for your reply early reply. The method is correct, however, I was looking for an automatic way of doing it in Python script. Jun 28 '17 at 8:36