0
$\begingroup$

Thank you for the great script.

I have tried to use this script, but I want a slightly different setup. Do you know how you can change this script so the pivot point is set to the bottom left back?

import bpy
from bpy import context as C

for z, co in [(o.bound_box[0][2], v.co) for o in C.selected_objects for v in o.data.vertices]:
co.z -= z 
$\endgroup$
1
  • $\begingroup$ We have no idea what you're talking about without more context! $\endgroup$
    – John Eason
    Jul 29, 2022 at 16:48

1 Answer 1

0
$\begingroup$

Something like this should do the trick.

import bpy
import numpy as np
from mathutils import Vector, Matrix


obj = bpy.context.object
mesh = obj.data

# get the lowest point in all 3 axes for the object bounding box
#this should be the bottom-left

bb = obj.bound_box
bb_locs = np.array([v[:] for v in bb])
bot_left = []

for i, row in enumerate(bb_locs.transpose()):
    # go through each row in the bounding box axes
    # if the axis is "Y"
    if i == 1:
        # get the greatest value in that row:
        val = max(row)
    else:
        # otherwise get the lowest value
        val = min(row)
    bot_left.append(val)
    
bot_left = Vector(bot_left)
    

# make a translation matrix that will move the mesh in the opposite direction
# leaving the origin in place.
mat = Matrix.Translation(-bot_left)
if mesh.is_editmode:
    bm = bmesh.from_edit_mesh(mesh)
    bm.transform(mat)
    bmesh.update_edit_mesh(me, False, False)
else:
    mesh.transform(mat)

mesh.update()

# then move the entire object by the matrix itself. 
# Which puts the object back where it was with the origin in the new location.

obj.matrix_world.translation = bot_left

Result:

enter image description here

$\endgroup$
3
  • 1
    $\begingroup$ Wow, thank you so much, can I ask you what I can change to make it the back rather than the front. also can it do it to multiple selected mesh's? i.e. all selected objects? Really sorry for the silly novice questions, I just have no clue about Python. very sorry in advance. !Valid XHTML. $\endgroup$
    – absuk
    Aug 1, 2022 at 8:15
  • $\begingroup$ I edited it to suit that need. $\endgroup$
    – Jakemoyo
    Aug 1, 2022 at 20:32
  • 1
    $\begingroup$ Perfect, thank you so much. $\endgroup$
    – absuk
    Aug 2, 2022 at 8:25

You must log in to answer this question.

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