# Getting global axis value of the vertex with the lowest value

In Python, Is there an operator that selects the vertex (or vertices if applies) that has the lowest value on a global axis (let's say Z).
I have an object that I need to select it's bottom vertex/vertices (the ones with the lowest Z global value) using Python, in order to move it's origin to the Median point among these vertices later. Here's a slightly shorter and faster way to do this:

import bpy

o  = bpy.context.object  # active object
mw = o.matrix_world      # Active object's world matrix

glob_vertex_coordinates = [ mw * v.co for v in o.data.vertices ] # Global coordinates of vertices

# Find the lowest Z value amongst the object's verts
minZ = min( [ co.z for co in glob_vertex_coordinates ] )

# Select all the vertices that are on the lowest Z
for v in o.data.vertices:
if (mw * v.co).z == minZ:
v.select = True

• Thank you for taking the time to answer my question, however, I'm getting an Error here: minZ = min( [ co.z for co in glob_vertex_coordinates ] ), an unexpected indent, and a unknown location (-1) – Georges Jun 12 '16 at 11:26
• Well now it worked!! I tried this several times with no luck, looks like I was doing something wrong, thank you, great answer! – Georges Jun 12 '16 at 11:32

I'm a noob when it comes to python but won't this do the job?

import bpy
import bmesh

object = bpy.data.scenes.objects["Cube"].data
vcount = len(object.vertices)
cube = bmesh.from_edit_mesh(object)

if (vcount > 0):
lowest = cube.verts
for i in range(vcount):
if (lowest.co.z > cube.verts[i].co.z):
lowest = cube.verts[i]

for v in cube.verts:
if (v.co.z == lowest.co.z):
v.select = True
else:
v.select = False
bmesh.update_edit_mesh(object, True)

• Thank you for your answer, I tried this script on a Cube object, it's selecting only one vertex, even though 4 vertices have the same Z value, is there a way to select all vertices with the same value? Reading the code, I expected it to select all vertices with the same Z, but that's not the case. – Georges Jun 12 '16 at 11:31

This code will find and select the lowest vertix: (Must be in Edit mode)

import bpy
import bmesh

obj = context.active_object
wm = obj.matrix_world
#data = obj.data
bm = bmesh.from_edit_mesh(obj.data)
vertices = [e for e in bm.verts]
minZ = 999999.8
for v in vertices:
world = wm * v.co
if (world < minZ):
minZ = world
lowest = v

lowest.select= True
bmesh.update_edit_mesh(obj.data, True)