# 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[0],v[1],v[2]))

if v_world[0] < minx:
minx = v_world[0]
if v_world[0] > maxx:
maxx = v_world[0]

if v_world[1] < miny:
miny = v_world[1]
if v_world[1] > maxy:
maxy = v_world[1]

if v_world[2] < minz:
minz = v_world[2]
if v_world[2] > maxz:
maxz = v_world[2]

• 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[0]
elif i[0] < x: x = i[0]
if z == None: z = i[2]
elif i[2] < z: z = i[2]
pos = pattern.matrix_local * pattern.location
position = pattern.matrix_world * mathutils.Vector((x, tuple(pos)[1], 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[0]
elif i[0] < x: x = i[0]
if z == None: z = i[2]
elif i[2] < z: z = i[2]
if y == None: y = i[1]
elif i[1] < y: y = i[1]
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.