How to create a plane that follows the dimensions of an object? I'm trying to create a plane object, which perfectly follows the selected object in x-z dimensions and also on the positioning and the origin of the axes (pivot). I messed up and I don't understand where to look and what.
This script generates a plane of equal size, but does not rely on the inverse matrix.
So the obtained plan has the dimensions of the input object (in this case the monkey) The position z does not interest me.
I'd like to get the same position with the same x, y origin as the monkey
this is the function in part of the code:

import bpy,mathutils,bmesh
from bpy import context
from mathutils import Vector


def createPlane(context):

    obj = context.object
    size= obj.dimensions
    loc= obj.location

    verts = ((0,0,0),(size.x,0,0),(size.x,size.y,0),(0,size.y,0))

    bm = bmesh.new()
    for v in verts:
        bm.verts.new((v[0], v[1], v[2]))
    bm.faces.new(bm.verts)

    bm.normal_update()

    me = bpy.data.meshes.new("")
    bm.to_mesh(me)

    plane = bpy.data.objects.new("", me)
    bpy.context.scene.collection.objects.link(plane)

createPlane(context)
Instead of using the dimensions property, create your own bounding box.


Create a list of the vertex positions matmultiplied by the objects world matrix. This list will hold the coordinates of the vertices in world space.
Get the min and max of the x and y property of the coordinate list.






def createPlane(context):

    obj = context.object
    coordinates = [obj.matrix_world @ v.co for v in obj.data.vertices]

    x_list = [co.x for co in coordinates]
    y_list = [co.y for co in coordinates]

    x_min, x_max = min(x_list), max(x_list)
    y_min, y_max = min(y_list), max(y_list)

    verts = ((x_min, y_min, 0),(x_min, y_max, 0),
             (x_max, y_max, 0),(x_max, y_min,0))

    bm = bmesh.new()
    [bm.verts.new((v[0], v[1], v[2])) for v in verts]
    bm.faces.new(bm.verts)

    bm.normal_update()

    me = bpy.data.meshes.new("")
    bm.to_mesh(me)

    plane = bpy.data.objects.new("", me)
    bpy.context.scene.collection.objects.link(plane)