adding plane with same X dimensions as other mesh


I am working on a script where I generate a different mesh every time, and I want to add a plane with the same width as the generated mesh. So max and min X value are the same for the plane.

How do I retrieve these values from a generated mesh. ( it is a different mesh each time, so i can not hard-code it ).

Thanks in advance.

from original mesh use bmesh and calclength and or calc the coordiantes… and then you can apply that lenght or coordinates to the new mesh


should this work on local or world space…?
here a snippet, could be simpler I guess but also depends on your needs

import bpy, mathutils as M

def center(n):
for obj in bpy.context.selected_objects:
    tmp = obj.to_mesh(bpy.context.scene, True, 'PREVIEW')
    x,y,z = [[[i] for v in tmp.vertices] for i in range(3)]
    loc = M.Vector((center(x),center(y),center(z)))
    size = (max(x)-min(x))/2

Perfect solution, thank you very much.

Hey, I have another question

With the above code, everything works fine already.
But now i want to alter de dimensions of the added mesh. Shoud be always around .25blender units. Shoud start approx 0.05units above lowest y and then 20 units below lowest y of reference.

I’ve been bending my mind around bmesh, but when i set coordinates, they reference the max(y) from above code wich is in global coord, but is in local, so my solution is al screwed-up

I’ve attached a blend showing what i need. Help is pretty welcome.