6
$\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$

2 Answers 2

8
$\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 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)
$\endgroup$
5
  • $\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
    Commented Jun 28, 2017 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
    Commented Jun 28, 2017 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
    Commented Jun 28, 2017 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
    Commented Jun 28, 2017 at 9:15
  • $\begingroup$ @batFINGER, good suggestions. Will amend code. $\endgroup$
    – TLousky
    Commented Jun 28, 2017 at 9:17
4
$\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$
1
  • $\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
    Commented Jun 28, 2017 at 8:36

You must log in to answer this question.

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