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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bpy | |
import bmesh | |
def print_vert_details(selected_verts): | |
num_verts = len(selected_verts) | |
print("number of verts: {}".format(num_verts)) | |
print("vert indices: {}".format([id.index for id in selected_verts])) | |
def get_vertex_data(object_reference): | |
bm = bmesh.from_edit_mesh(object_reference.data) | |
selected_verts = [vert for vert in bm.verts if vert.select] | |
print_vert_details(selected_verts) | |
object_reference = bpy.context.active_object | |
get_vertex_data(object_reference) |