quick noob script question. (get object height / DimZ)

Hey,

How do I get the height of an object in Python?

I couldn’t find any clear info on this…

story:

I’m trying to write a simple script which would position some objects for me.
The goal is for the objects to have their bottom left corner (in “numpad 1” view) to be aligned.

This is what I came up with so far:

#!BPY
"""
Name: 'Drop to ground and line up back'
Blender: 245
Group: 'Object'
Tooltip: 'Put some useful info here'
"""

import Blender
from Blender import Window, sys
import bpy

objList = Blender.Object.GetSelected()
for obj in objList :
		obj.LocZ = obj.DimZ/2
		obj.LocX = obj.DimX/2
Blender.Redraw()

The error probably is situated at the obj.LocZ = obj.DimZ/2 lines. I couldn’t really find any clear info on how to get the sizes…

Any and all help and tips appreciated!

Cheers,
Jeroen

Try


#!BPY 
""" 
Name: 'Drop to ground and line up back' 
Blender: 245 
Group: 'Object' 
Tooltip: 'Put some useful info here' 
""" 
 
import Blender 
from Blender import Window, sys 
import bpy 
 
# align coords 
alignX = 2.0 
alignZ = 0.0 
 
objList = Blender.Object.GetSelected() 
for obj in objList : 
        # calculate location of lower left corner of the bounding box 
        bb = obj.getBoundBox() 
        # pick some corner 
        corner = bb[0] 
        print corner 
        # get deltas against center 
        deltaX = corner[0] - obj.LocX 
        deltaZ = corner[2] - obj.LocZ 
        # and project object according to it 
        obj.LocX = alignX - deltaX 
        obj.LocZ = alignZ - deltaZ 
Blender.Redraw()

Hey BeBraw,

That worked wonders!

But dang, that python scripting sure looks more complicated then I thought it would. I guess I’ll just have to dive in one day.

Thanks a bunch for your help.

Cheers,
Jeroen