# Translate object using lowest Z value python

I have an object located in the origin (0,0,0). I wonder how I can translate it along the z-axis where the lowest -z value of the object will be translated to z value 0 as shown below:

• Loop over the vertices, find the one with the lowest z value, move the object up -whatever_the_previous_got_you :-) I'll post an answer in a few... Commented Feb 15, 2017 at 12:42
• related blender.stackexchange.com/a/42110/15543 in that it moves the origin to bottom. Commented Feb 15, 2017 at 14:21

Here is a simple script that accomplishes this...let me know if you have any questions.

import bpy

# get a reference to the active object
obj = bpy.context.object

# get the minimum z-value of all vertices after converting to global transform
lowest_pt = min([(obj.matrix_world * v.co).z for v in obj.data.vertices])

# transform the object
obj.location.z -= lowest_pt


Note

For 2.8 replace * with @ for matrix multiplication.

lowest_pt = min([(obj.matrix_world @ v.co).z for v in obj.data.vertices])

• Can also find the lowestZ in one line instead of a loop thus: lowestZ = min( [ ( obj.matrix_world * v.co ).z for v in obj.data.vertices ] ) Commented Feb 15, 2017 at 13:04
• Adding object location to local vert coordinate is not converting to global location. See comment above. Commented Feb 15, 2017 at 14:25
• @TLousky Thanks! Your method also works correctly with rotation and scale that I wasn't thinking about when I posted originally. I have edited my answer to include this technique... Commented Feb 15, 2017 at 14:50
• @batFINGER I was fooled into thinking this b/c I was not using a rotated or scaled object. Commented Feb 15, 2017 at 14:50
• @pycoder what if the object was an armature? It doesn't work in that case as this solution only works for mesh as it uses the mesh vertices
– Tak
Commented Mar 5, 2017 at 2:49