Scale Edges to World X Center

I’m trying to make a script that will align all selected mesh components to grid X center. Usually I would do this by scaling with the orgin set to world center but the script will always scale by the Median Point no matter what I do. Any help would be appreciated

import bpy
bpy.ops.transform.resize(value=(-0, 1, 1), orient_type='CURSOR', orient_matrix=((1, 0, -0), (0, 1, 0), (0, 0, 1)), orient_matrix_type='CURSOR', constraint_axis=(True, False, False))

why not just do it with bmesh?

import bpy, bmesh
obj = bpy.context.active_object
bm = bmesh.from_edit_mesh(obj.data)

selected_verts = [v for v in bm.verts if v.select]
for v in selected_verts:
    v.co = (0, v.co[1], v.co[2])
    
bmesh.update_edit_mesh(obj.data)

Because I don’t know what I’m doing :slight_smile: I haven’t figure out the difference between bpy.ops and bmesh.

Thank you but, the code you wrote scale the verts to the objects center. If I transform the object it will no longer snap the verts to world center. Do you know how I can always scale to world origin?

import bpy, bmesh

bpy.ops.transform.resize(value=(0, 1, 1), orient_type='CURSOR', center_override=(0, 0, 0), constraint_axis=(True, False, False))

The above is working for me now.