Sometimes we need to place a marker (Empty) at a given point on our mesh. I use this often to define a pivot point. But manually hopping in and out of edit mode to add an Empty soon becomes lame. This is my solution. Run this in edit mode, select as many verts as you wish.
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
# be in edit mode to run this code | |
import bpy | |
from mathutils import Vector | |
myob = bpy.context.active_object | |
bpy.ops.object.mode_set(mode = 'OBJECT') | |
# collect selected verts | |
selected_idx = [i.index for i in myob.data.vertices if i.select] | |
original_object = myob.name | |
for v_index in selected_idx: | |
# get local coordinate, turn into word coordinate | |
vert_coordinate = myob.data.vertices[v_index].co | |
vert_coordinate = myob.matrix_world * vert_coordinate | |
# unselect all | |
for item in bpy.context.selectable_objects: | |
item.select = False | |
# this deals with adding the empty | |
bpy.ops.object.add(type='EMPTY', location=vert_coordinate) | |
mt = bpy.context.active_object | |
mt.location = vert_coordinate | |
mt.empty_draw_size = mt.empty_draw_size / 4 | |
bpy.ops.object.select_all(action='TOGGLE') | |
bpy.ops.object.select_all(action='DESELECT') | |
# set original object to active, selects it, place back into editmode | |
bpy.context.scene.objects.active = myob | |
myob.select = True | |
bpy.ops.object.mode_set(mode = 'EDIT') |