# How can I get a vertex count for an edge loop in Python for Blender 2.8?

I have an object that consists of two polygons. I'm trying to get a vertices count for the first polygon so I can select it's last two vertexes by index. I know that it starts at Index 1.

I can use

bm.verts[firstindex].select = True

bm.verts[secondindex].select = True


and then bpy.ops.mesh.loop_multi_select(ring=False) to select the edge loop, but is there any way I can get a vertex count only for the vertices in the edge loop? Thanks.

## 2 Answers

Or you could also do:

import bpy
import bmesh

selected_verts = [v for v in bpy.context.active_object.data.vertices if v.select]
count = len(selected_verts)
print(count)
$$$$

• This just gives me a value of zero for my selected edge loop. I tried selecting every vertex and ran this and it still gave me zero for the count value. Oct 5 '19 at 21:47
• Is the edge loop the boundary of the mesh? Did you select the vertex in edit mode? Oct 8 '19 at 10:00
• Thanks, changing the mode to Edit did the trick. I must have had it in Object mode last time. Oops. Oct 8 '19 at 18:01
import bpy
import bmesh

mode = bpy.context.active_object.mode
selectedVerts = [v for v in bpy.context.active_object.data.vertices if v.select]
count=0
for v in selectedVerts:
count+=1
print(count)

bpy.ops.object.mode_set(mode=mode)
`