5
$\begingroup$

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.

Vertex select and results of "Ctrl+numpad+"

$\endgroup$
5
$\begingroup$

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.

enter image description here

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

import bpy, bmesh

# Assuming our object is active and in edit mode
bm = bmesh.from_edit_mesh( bpy.context.object.data )

# Get active vertex (assuming there is only 1 selected)
v = bm.select_history.active

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

bm.select_flush( True )
$\endgroup$
  • $\begingroup$ 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 $\endgroup$ – Debaditya Jun 28 '17 at 8:42
  • $\begingroup$ 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! $\endgroup$ – Debaditya Jun 28 '17 at 8:55
  • $\begingroup$ 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. $\endgroup$ – TLousky Jun 28 '17 at 9:10
  • 1
    $\begingroup$ @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. $\endgroup$ – batFINGER Jun 28 '17 at 9:15
  • $\begingroup$ @batFINGER, good suggestions. Will amend code. $\endgroup$ – TLousky Jun 28 '17 at 9:17
3
$\begingroup$

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

Face Step

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.

$\endgroup$
  • $\begingroup$ 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. $\endgroup$ – Debaditya Jun 28 '17 at 8:36

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.