# Get the selected median point in python?

During edit mode, how do I get the coordinates of the median pivot point (position of the transform manipulator) using python?

This information is shown in the Transform panel of the properties sidebar in the 3d view.

• Shift+s->'Cursor To Selected', this will move the 3D cursor to the Objects Origin. Enter Edit Mode and now you can use Shift+s->'Selection To Cursor(Offset)' to move anything to that point. Commented Feb 20, 2015 at 8:20

You can calculate it quite easy:

import bpy
from mathutils import Vector

ob = bpy.context.object
ob.update_from_editmode()

me = ob.data
verts_sel = [v.co for v in me.vertices if v.select]

pivot = sum(verts_sel, Vector()) / len(verts_sel)

print("Local:", pivot)
print("Global:", ob.matrix_world * pivot)


You could also use the bmesh module, but the standard API appears to be faster despite the update operation:

import bpy
import bmesh
from mathutils import Vector

ob = bpy.context.object
me = ob.data

bm = bmesh.from_edit_mesh(me)
verts_sel = [v.co for v in bm.verts if v.select]

pivot = sum(verts_sel, Vector()) / len(verts_sel)

print("Local:", pivot)
print("Global:", ob.matrix_world * pivot)


## for 2.8

import bpy
import bmesh
from mathutils import Vector

ob = bpy.context.object
me = ob.data

bm = bmesh.from_edit_mesh(me)
verts_sel = [v.co for v in bm.verts if v.select]

pivot = sum(verts_sel, Vector()) / len(verts_sel)

print("Local:", pivot)
print("Global:", ob.matrix_world @ pivot)

• Technically, both of these return the mean, not the median? I guess there's not usually much in it... Commented Jul 29, 2022 at 16:39
• @RobinBetts You are right but what Blender displays is actually the arithmetic mean. If I have three connected vertices with the Z coordinates 1, 0, and -2.5, then the median is the second value. However, what Blender shows me is -0.5 (-1.5 / 3) instead of 0. Commented Aug 18, 2022 at 18:27