2
$\begingroup$

When i try to create verts with BMesh i get always the same verts index.

bm = bmesh.from_edit_mesh(active_obj.data)
for i in range(20):
    vert = bm.verts.new((0.0, 0.0, 0.0))
    print(vert.index)

index of all 20 verts will be -1.

How to get right index or correct it manually?

$\endgroup$
0

1 Answer 1

5
$\begingroup$

you'll have to reassign the vertices indexes using an built in function or using your own code as mentioned in the DOCs

index_update()

Initialize the index values of this sequence.
This is the equivalent of looping over all elements and assigning the index values.

so your code should be :

bm = bmesh.from_edit_mesh(active_obj.data)
for i in range(20):
    vert = bm.verts.new((0.0, 0.0, 0.0))
    vert.index = len(bm.verts)
    print(vert.index)

or use

bm.verts.index_update()
$\endgroup$
1
  • $\begingroup$ bm.verts.index_update() is correct. $\endgroup$
    – mifth
    May 28, 2015 at 21:56

You must log in to answer this question.

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