5
$\begingroup$

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.

$\endgroup$
1
  • $\begingroup$ 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. $\endgroup$ Commented Feb 20, 2015 at 8:20

1 Answer 1

9
$\begingroup$

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)
$\endgroup$
2
  • $\begingroup$ Technically, both of these return the mean, not the median? I guess there's not usually much in it... $\endgroup$
    – Robin Betts
    Commented Jul 29, 2022 at 16:39
  • $\begingroup$ @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. $\endgroup$
    – CodeManX
    Commented Aug 18, 2022 at 18:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .