0
$\begingroup$

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.

$\endgroup$

2 Answers 2

2
$\begingroup$

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)
```
$\endgroup$
3
  • $\begingroup$ 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. $\endgroup$
    – James
    Commented Oct 5, 2019 at 21:47
  • 1
    $\begingroup$ Is the edge loop the boundary of the mesh? Did you select the vertex in edit mode? $\endgroup$ Commented Oct 8, 2019 at 10:00
  • $\begingroup$ Thanks, changing the mode to Edit did the trick. I must have had it in Object mode last time. Oops. $\endgroup$
    – James
    Commented Oct 8, 2019 at 18:01
0
$\begingroup$
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)
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .