Featured post

new redirect for blender.org bpy docs.

http://www.blender.org/api/blender_python_api_current/ As of 10/11 november 2015 we can now link to the current api docs and not be worr...

July 11, 2011

getting index of currently selected vertex ( or vertices)

this tells you the index of the currently selected vertex (or if more than one, then it returns the list of selected vertices)
# you must be in 'OBJECT' mode to run these.
>>> [i.index for i in bpy.context.active_object.data.vertices if i.select == True]
[5]
# or slightly shorter, when i.select returns False the element is discarded,
# but when i.select returns True, the if statement compares True with True. (overkill)
>>> [i.index for i in bpy.context.active_object.data.vertices if i.select]
[5]
# or use shorthand to access active_object (more pythonic ):
>>> current_object = bpy.context.active_object
>>> [i.index for i in current_object.data.vertices if i.select]
[5]

# to get a coordinate: (will return all selected vertices if more than one selected)
>>> [i.co for i in bpy.context.active_object.data.vertices if i.select]
[Vector((2.4389050006866455, -3.9095726013183594, 0.9682117700576782))]
Here is a similar snippet that works with bmesh and updates without requiring to enter/exit edit mode.

What about Faces?

Please see this post, it shows two ways.