adding plane with same X dimensions as other mesh

Hey,

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

best

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):
    return(min(n)+(max(n)-min(n))/2)
    
for obj in bpy.context.selected_objects:
    tmp = obj.to_mesh(bpy.context.scene, True, 'PREVIEW')
    tmp.transform(obj.matrix_world)
    x,y,z = [[v.co[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
    bpy.ops.mesh.primitive_plane_add(radius=size,location=loc)
    bpy.data.meshes.remove(tmp)

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 bmesh.verts.co is in local, so my solution is al screwed-up

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