3
$\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$
  • $\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$ – MarcClintDion Feb 20 '15 at 8:20
4
$\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)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.