# How to set median value in edit mode trough script?

Its possible to change that's median (global) value trough script? • The question is a bit unclear. Are you looking to transform the selected faces, so that their median global location will be some other xyz vector value? Aug 4 at 12:48
• yes that's right, i get confused due there are no tooltips if hover on their median value Aug 4 at 12:54

BMesh version.

For an edit mode script can also use an edit mode bmesh.

Test script, move selected verts such that their mean global location is (1, 0, 0)

import bpy
import bmesh
from mathutils import Vector

coord = Vector((1, 0, 0))
space = 'GLOBAL'

context = bpy.context

ob = context.edit_object
mw = ob.matrix_world
coord = coord if space == 'LOCAL' else mw.inverted() @ coord
me = ob.data

bm = bmesh.from_edit_mesh(me)
verts = [v for v in bm.verts if v.select]
# need at least one selected
o = sum((v.co for v in verts), Vector()) / len(verts)

bmesh.ops.translate(
bm,
verts=verts,
vec= coord - o
)

bmesh.update_edit_mesh(me)


You should calculate the midpoint manually, then the difference vector that moves vertices and finally move selected parts in local coordinates because blender stores vertex-locations in local coordinates.

this code does such work: (just enter your desired value into world_pos variable)

import bpy
from mathutils import Vector as vec, Matrix as mat

# this is your input world position for center
world_pos = vec((4,0,0))

def move_center(world_pos:vec):
obj = bpy.context.object
bpy.ops.object.mode_set(mode='OBJECT')
selected_verts = [v for v in obj.data.vertices if v.select]
print(selected_verts)
if len(selected_verts) == 0:
return
center_local = vec((0,0,0))
for v in selected_verts:
center_local += v.co
center_local /= len(selected_verts)
local_pos = obj.matrix_world.inverted() @ world_pos
dif = local_pos - center_local
for v in selected_verts:
v.co += dif
bpy.ops.object.mode_set(mode='EDIT')

if __name__ == "__main__":
move_center(world_pos)

• thanks for your answer, i just run that's script in edit mode with selected face but get error, prnt.sc/1jcnv03 it seem the script doesn't work on mine could you please clarify or edit your answer? Aug 5 at 8:02
• @cheatPKL check this one out Aug 5 at 8:48
• thank you, now its work as i wanted Aug 5 at 12:34