1
$\begingroup$

How to draw a circle hole or a square hole by bmesh on the plane object? I tried with below but failed it only draws circle rather than a hole.

bm=bmesh.new()
ret=bmesh.ops.create_circle(
    bm,
    cap_ends=False,
    radius=1.8,
    segments=8)
#print('circleret:',ret)
bmesh.ops.translate(
    bm,
    verts=ret['verts'],
    vec=(5.0, 24.0, 0.0))
mycircleface = bm.faces.new(ret['verts'])
me1 = bpy.data.meshes.new("Circle")
bm.to_mesh(me1)
$\endgroup$

1 Answer 1

3
$\begingroup$

Round or square hole in round or square mesh.

enter image description here

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.

$\endgroup$
2
  • $\begingroup$ Thanks a lot!!!Very helpful!!! $\endgroup$
    – Derekcbr
    Commented Jun 24, 2020 at 10:34
  • 2
    $\begingroup$ Thankyou. If it answers your question please consider accepting by pressing the green check. If it was helpful consider upvoting. Re your latest question. The title suggests using bmesh and moving faces, the code is finding the min / max of the local z coordinate of the mesh vertices. There are numerous question re transforming vertices with python. $\endgroup$
    – batFINGER
    Commented Jun 28, 2020 at 6:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .