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.


enter image description here

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
| improve this answer | |
  • $\begingroup$ 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) $\endgroup$ – Georges Jun 12 '16 at 11:26
  • 1
    $\begingroup$ Well now it worked!! I tried this several times with no luck, looks like I was doing something wrong, thank you, great answer! $\endgroup$ – 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[0].objects["Cube"].data
vcount = len(object.vertices)
cube = bmesh.from_edit_mesh(object)

if (vcount > 0):
    lowest = cube.verts[0]
    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
            v.select = False
bmesh.update_edit_mesh(object, True)
| improve this answer | |
  • $\begingroup$ 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. $\endgroup$ – 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[2] < minZ):
       minZ = world[2]
       lowest = v

lowest.select= True
bmesh.update_edit_mesh(obj.data, True)
| improve this answer | |
New contributor
Rodolfo Leibner is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

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.