1
$\begingroup$

I want to select a vertex from a specific edge. The closest I have been able to get is by writing:

p1 = o.data.edges[edgeIdx].vertices[0]

However, according to the documentation on MeshEdge, I can only get the vertex indices by using this method. Is there any way to select a vertex that lies on a specific edge?

Thanks!

$\endgroup$
0
$\begingroup$

If you don't want to use BMesh, the following will work:

import bpy

data = bpy.context.scene.objects.active.data
edges = data.edges     # collection of all edges
verts = data.vertices  # collection of all vertices

# must be in object mode of course
bpy.ops.object.mode_set(mode = 'OBJECT')

# the indices given by MeshEdge.vertices correspond to the collection of vertices
verts[edges[0].vertices[0]].select = True

# go back into edit mode to see the new selection
bpy.ops.object.mode_set(mode = 'EDIT')

BMesh can be a bit simpler though...

import bpy
import bmesh

data = bpy.context.scene.objects.active.data

bm = bmesh.from_edit_mesh(data)
bm.edges[0].verts[0].select = True
$\endgroup$
  • $\begingroup$ That works, thanks! In general, do people tend to use bmesh for these kinds of operations? I am fairly new to blender, and have used them a little bit, but usually if I can do an operation without a bmesh I will $\endgroup$ – Kyle Byrne Mar 31 '18 at 18:04
  • $\begingroup$ @KyleByrne As I understand it, BMesh is the best way to go for the most part because it has more features and is more performant in many cases...see sambler's answer here: blender.stackexchange.com/a/55586/28015. I don't have time to dig into it right now, but I'd recommend using it unless you have a reason to otherwise, or ask a question about that (check if it's already been asked though). There are plenty of examples on here and GitHub for both methods (BMesh didn't come until like 2.76 IIRC), so you shouldn't have a problem writing most code. $\endgroup$ – JakeD Mar 31 '18 at 19:35

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.