I want to select vertices by their indices (by vertex id) Like a python script,so that i can write the vertex id into it, and run the script,and it would automatically select those vertices

there is already an answer (python script) ,but it only works with one vertex when i tried with more than 2 vertices,it does not work : How Could I Select a vertex by its ID?


I have modified the code from this answer to solve the problem, where I have replaced if vert.index == index: to if vert.index in indices: where indices= [1, 2, ...]

example :

import bpy
import bmesh

indices = [1, 3, 4, 7, 8] 

obj = bpy.context.object
me = obj.data
bm = bmesh.from_edit_mesh(me)

vertices= [e for e in bm.verts]
oa = bpy.context.active_object

for vert in vertices:
    if vert.index in indices:
        vert.select = True
        vert.select = False

bmesh.update_edit_mesh(me, True)      
| improve this answer | |
  • $\begingroup$ Another approach would be to remove the else: vert.select=False so that it only extends the selection, then manually de-select all if you want to start again. $\endgroup$ – sambler Apr 2 '16 at 9:09
  • $\begingroup$ same thing for the faces? face in faces ? $\endgroup$ – June Wang Oct 18 '19 at 6:03

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