Its possible to change that's median (global) value trough script?

enter image description here

  • 1
    $\begingroup$ 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? $\endgroup$
    – TLousky
    Aug 4 at 12:48
  • $\begingroup$ yes that's right, i get confused due there are no tooltips if hover on their median value $\endgroup$
    – cheatPKL
    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)

        vec= coord - o

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
    selected_verts = [v for v in obj.data.vertices if v.select]
    if len(selected_verts) == 0:
    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

if __name__ == "__main__":
  • $\begingroup$ 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? $\endgroup$
    – cheatPKL
    Aug 5 at 8:02
  • $\begingroup$ @cheatPKL check this one out $\endgroup$ Aug 5 at 8:48
  • $\begingroup$ thank you, now its work as i wanted $\endgroup$
    – cheatPKL
    Aug 5 at 12:34

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.