# Add created vertices to a list

My goal is to add every created vertice to a list.

import bpy
import bmesh
bm = bmesh.from_edit_mesh(bpy.context.edit_object.data)
v = bm.verts.new(loc)
bm.verts.index_update()
bm.verts.ensure_lookup_table()
vertlist = []
vertlist.extend([v])
print(vertlist)
return {v}


This is what I get as output:  [<BMVert(0x0000020E20C3CF20), index=12>] [<BMVert(0x0000020E20C3CF58), index=13>] [<BMVert(0x0000020E20C3CF90), index=14>]

This is what I would like: [<BMVert(0x0000020E20C3CF20), index=12>,<BMVert(0x0000020E20C3CF20), index=13>,<BMVert(0x0000020E20C3CF20), index=14>]

• Loading an edit mode bmesh, updating and reindexing it every time a new vertex is added is complete overkill. Which is why I pointed out making only one bmesh in this answer as a class property ... or pass the bm to the method. – batFINGER May 2 '18 at 12:04
• What I want to do is change the color of each vertex in the list using Bgl and so I have to make and update the list while in edit mode. – sajdnv May 2 '18 at 19:14
• Ok let's put it another way. Let's say you add 1000 verts to your list to display in bgl. I contend you can create the bmesh once, add 1000 verts then update once. via your method above you create 1000 bmeshes and update a 1000 times. – batFINGER May 2 '18 at 20:14
• I’m just using this example of what I want to do so I can get right to the point. I plan on implementing this into what u showed me. – sajdnv May 2 '18 at 20:28

You need to define your vertlist variable outside of the function. Currently, vertlist exists only within the scope of the add_vert function. You can either define it before hand:

vertlist = []

or add a try statement to check if vertlist already exists:
def add_vert(loc):