6
$\begingroup$

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:

enter image description here

$\endgroup$
2
  • $\begingroup$ 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... $\endgroup$
    – JakeD
    Commented Feb 15, 2017 at 12:42
  • $\begingroup$ related blender.stackexchange.com/a/42110/15543 in that it moves the origin to bottom. $\endgroup$
    – batFINGER
    Commented Feb 15, 2017 at 14:21

1 Answer 1

6
$\begingroup$

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])
$\endgroup$
9
  • 2
    $\begingroup$ 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 ] ) $\endgroup$
    – TLousky
    Commented Feb 15, 2017 at 13:04
  • 2
    $\begingroup$ Adding object location to local vert coordinate is not converting to global location. See comment above. $\endgroup$
    – batFINGER
    Commented Feb 15, 2017 at 14:25
  • 1
    $\begingroup$ @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... $\endgroup$
    – JakeD
    Commented Feb 15, 2017 at 14:50
  • 1
    $\begingroup$ @batFINGER I was fooled into thinking this b/c I was not using a rotated or scaled object. $\endgroup$
    – JakeD
    Commented Feb 15, 2017 at 14:50
  • $\begingroup$ @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 $\endgroup$
    – Tak
    Commented Mar 5, 2017 at 2:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .