1
$\begingroup$

This question already has an answer here:

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?

$\endgroup$

marked as duplicate by someonewithpc, p2or, PGmath, David Apr 1 '16 at 22:08

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

4
$\begingroup$

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
    else:
        vert.select = False

bmesh.update_edit_mesh(me, True)      
$\endgroup$
  • $\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 at 6:03

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