How could I select one vertex from my mesh if I know ID of that vertex? I enabled bpy.app.debug = True
and I can see all IDs but cant find a specific one.
3
$\begingroup$
$\endgroup$
-
$\begingroup$ do you mean index ? $\endgroup$ – Chebhou Apr 5 '15 at 14:08
-
$\begingroup$ Yup, Im not sure whats the correct term, you can call it index, select vertex by number $\endgroup$ – Slobodan Vidovic Apr 7 '15 at 7:41
3
$\begingroup$
$\endgroup$
here the answere:
import bpy
import bmesh
index = 0 # here the index you want select please change
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 == index:
vert.select = True
else:
vert.select = False
bmesh.update_edit_mesh(me, True)
-
-
$\begingroup$ I added more then one number in index with comma but it does not work, what else do I need to change :) $\endgroup$ – Slobodan Vidovic Apr 8 '15 at 15:47
1
$\begingroup$
$\endgroup$
I would like to add to yhoyos answer, that a vertex can be selected by replacing the for-loop with
bpy.ops.mesh.select_all(action='DESELECT')
bm.verts[index].select = True
Also, if you don't care about the previous selections, just using
bm.verts[index].select = True
should be significantly faster for large meshes
-
1$\begingroup$ Agree re no need for for loop. Btw it's
bm.verts
and will need tobm.verts.ensure_lookup_table()
to access via index, and maybe add the checkabs(index) < len(bm.verts)
$\endgroup$ – batFINGER Feb 21 at 14:19