Any suggestions as to how to select (in python) one specific vertex of a septagon (seven vertex mesh circle)? When I do it manually, it doesn't show up as a command or function in the python info window for me to copy into my python code.

So far I have this code which doesn't throw an error, but doesn't achieve the desired effect, either ... after running, all vertices are selected instead of just vertex 0.

import bpy
import bmesh
bpy.ops.mesh.primitive_circle_add(vertices=7, radius=1, enter_editmode=True, location=(0, 0, 0))



2 Answers 2


Have to select in object mode

To select mesh vertices using me.vertices[i].select need to set in object mode, and toggle into edit mode.

When a new primitive is added all the geometry is selected by default.

Here the mesh is added in object mode (without toggling into edit mode) all geometry is deselected (brute force) , vertex index 0 selected, and then toggle into edit mode.

import bpy
context = bpy.context

bpy.ops.mesh.primitive_circle_add(vertices=7, radius=1, enter_editmode=False, location=(0, 0, 0))
ob = context.object
me = ob.data
for g in me.vertices[:] + me.edges[:] + me.polygons[:]:
    g.select = False

me.vertices[0].select = True


Please note. When an object is created with an operator the object and mesh are given default names, "Circle" in this case. If another is added then the names may or may not be "Circle" if there is another with same name.

The newly created object will always be ob = context.object and its data part, mesh in this case ob.data. (suppose I'm saying, pays to get out of the habit of bpy.data.objects["What the first one's name is"])

or use bmesh, and load in the edit mesh and fix. (as answered by Leander while writing this), however this uses bmesh in conjunction with the add primitive operator.

import bpy
context = bpy.context
import bmesh
bpy.ops.mesh.primitive_circle_add(vertices=7, radius=1, enter_editmode=True, location=(0, 0, 0))
ob = context.edit_object
me = ob.data
bm = bmesh.from_edit_mesh(me)
for v in bm.verts:
    v.select = not v.index
  • $\begingroup$ Thanks batFINGER. For the first code sample you were so nice to provide, how would I make vertex[0] active, rather than merely selected? $\endgroup$
    – vndep
    Jul 15, 2019 at 15:11
  • 1
    $\begingroup$ AFAIK need bmesh for that. see blender.stackexchange.com/questions/16238/… and blender.stackexchange.com/questions/30582/… Agree with @Leander, for most cases, it's best to use bmesh to edit and manipulate meshes. $\endgroup$
    – batFINGER
    Jul 15, 2019 at 15:28
  • $\begingroup$ Amazing that there is no mention of which mode works and does not work in the documentation. Also amazing that bpy.ops.mesh.select_random() only works in Edit Mode. Is there some reasoning behind this madness? $\endgroup$
    – james_t
    Apr 1, 2021 at 18:35

Please use the bmesh module to edit and manipulate meshes. This answer describes how read and write from regular meshes. Use the bmesh operator to create the circle.

import bpy
import bmesh

scene = bpy.context.scene

# create new mesh
me = bpy.data.meshes.new('mesh')
# create new object
ob = bpy.data.objects.new("object", me)

# link object to scene and set it as active
bpy.context.view_layer.objects.active = ob

# 2.79
#scene.objects.active = ob
#ob.select = True

# create bmesh from mesh
bm = bmesh.new()

# create a circle
        #diameter=0.5, # < 2.79

# select bmesh vertex, need to ensure_lookup_table on the
# bmverts sequence before
bm.verts[0].select = True

# write bmesh to mesh and update mesh

# enter edit mode
  • $\begingroup$ The code above threw an error on the following line: scene.objects.link(ob) ... The error message was 'AttributeError: 'bpy_prop_collection' object has no attribute 'link' ... I am running 2.8 and cut-and-pasted all of your code into a clean sheet of the text editor. $\endgroup$
    – vndep
    Jul 15, 2019 at 14:58
  • 1
    $\begingroup$ @vndep For future reference, please add "2.8" somewhere in the question. I have updated the code for 2.8. Also try using the console to debug missing functions. $\endgroup$
    – Leander
    Jul 15, 2019 at 15:10

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.