Round or square hole in round or square mesh.

Would be many ways to skin this cat.
- Add a plane remove its one face. Size
square_size
- Subdivide the plane equally using
cuts
- Add a circle with
4 * (cuts + 1) segments, radius circle_radius
- Bridge the loops from square to circle
Test script.
import bpy
import bmesh
cuts = 3
square_size = 1
circle_radius = 2
context = bpy.context
collection = context.collection
me = bpy.data.meshes.new("Hole")
bm = bmesh.new()
bmesh.ops.create_grid(
bm,
x_segments=2,
y_segments=2,
size=square_size,
)
bm.faces.remove(bm.faces[:].pop())
bmesh.ops.subdivide_edges(
bm,
edges=bm.edges,
cuts=cuts,
)
bmesh.ops.create_circle(
bm,
segments=4 * (cuts + 1),
radius=circle_radius,
)
bmesh.ops.bridge_loops(
bm,
edges=bm.edges,
)
bm.to_mesh(me)
ob = bpy.data.objects.new("Hole", me)
collection.objects.link(ob)
This makes one of each as mesh and hole. Circle in circle (Square in square) can be done as above, simply making one twice.
Could wire this up similarly to
Create Circle with Inner Radius
giving option of square / circle inner outer and ngon fill.
See also
How can I morph a flat plane to be a flat cirlce? re morphing one to another.