3
$\begingroup$

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.

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

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)      
$\endgroup$
  • $\begingroup$ Tnx, this is working just perfect $\endgroup$ – Slobodan Vidovic Apr 7 '15 at 7:44
  • $\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$

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

$\endgroup$
  • 1
    $\begingroup$ Agree re no need for for loop. Btw it's bm.verts and will need to bm.verts.ensure_lookup_table() to access via index, and maybe add the check abs(index) < len(bm.verts) $\endgroup$ – batFINGER Feb 21 at 14:19

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.