# Trouble with getting global vertex positions

I am working on a siding generator script and I have most of it done, but I am having some trouble with one of the features. You can use a plane as a template object, and the script gets its position and rotation and tries to figure out the smallest "x" and "z" values. That way it can place the siding object at that position. It has to use the smallest numbers because the siding builds to the right and up. Here is the .blend file, and here is the addon.

Steps to problem: Install Addon > Select Plane > Add Siding > Click "From Object", note how position is correct. Delete Siding > Rotate Plane 90 degree on z > Add Siding, note how it is not at 0.0 on z

EDIT: the lines in question begin around line 1564

A while back I created a script to create a bounding box around a selection of objects. To get the min and max values I used the following code -

minx, miny, minz = (999999.0,)*3
maxx, maxy, maxz = (-999999.0,)*3
for obj in context.selected_objects:
for v in obj.bound_box:
v_world = obj.matrix_world * mathutils.Vector((v,v,v))

if v_world < minx:
minx = v_world
if v_world > maxx:
maxx = v_world

if v_world < miny:
miny = v_world
if v_world > maxy:
maxy = v_world

if v_world < minz:
minz = v_world
if v_world > maxz:
maxz = v_world

• The only problem with this is that you convert by matrix_world first, I need the local smallest "x" and "y" values. I figured it out though, just check my answer. – BlendingJake Oct 14 '14 at 14:04

I figured it out, I had been praying about it and I had this thought that it might be that the "y" value was incorrect so when it was converted by matrix_world it was throwing it off. It originally was this:

       verts = [vert.co for vert in pattern.data.vertices] #get vertex data
tup_verts = [vert.to_tuple() for vert in verts] #convert to tuples
x = None; z = None
for i in tup_verts: #find smallest x and z values
if x == None: x = i
elif i < x: x = i
if z == None: z = i
elif i < z: z = i
pos = pattern.matrix_local * pattern.location
position = pattern.matrix_world * mathutils.Vector((x, tuple(pos), z)) #get world space
ob.location = tuple(position)


By changing it to this:

       verts = [vert.co for vert in pattern.data.vertices] #get vertex data
tup_verts = [vert.to_tuple() for vert in verts] #convert to tuples
x = None; z = None; y = None
for i in tup_verts: #find smallest x and z values
if x == None: x = i
elif i < x: x = i
if z == None: z = i
elif i < z: z = i
if y == None: y = i
elif i < y: y = i
position = pattern.matrix_world * mathutils.Vector((x, y, z)) #get world space
ob.location = tuple(position)


It works! I added in the y value straight from local space instead of converting the objects.position by matrix_local just to get the "y" position then going back to matrix_world seems to have been the problem.