Block with rounded edges in python I can easily make a primitive box with python code. But I would like to make the edges parallel to the z-axis rounded with a given radius. Sort of like the picture below but without all the subdivision. (that was just me being bad at Blender). Does anyone know a way to script such an object with specified height, width depth and corner radius?

EDIT: I found this link, but it is not easily translated to python.
https://www.loekvandenouweland.com/content/round-corners-only-on-x-y-plane-in-blender.html
BMesh script.

&quot;Spam tin&quot; created with script below, in edit mode. Note has ngon top and bottom.
The bmesh equivalent of example linked in question using bpy.ops.mesh.bevel(...)

which is pretty much the bmesh.ops.bevel equivalent.
Select the four vertical edges How to select with python code only vertical edges from cube? and pass into operator.
Test script, run in OBJECT mode.
import bpy
import bmesh
from mathutils import Vector
context = bpy.context

corner_radius = 0.2 # 0.5 &gt; cylinder 
corner_segments = 5
width, depth, height = (1.5, 1, 2)

bpy.ops.mesh.primitive_cube_add()
ob = context.object
me = ob.data
bm = bmesh.new()
bm.from_mesh(me)

bm.edges.ensure_lookup_table()
# scale first to keep corners round
bmesh.ops.scale(
        bm,
        verts=bm.verts,
        vec=(width, depth, height),
        )  
bmesh.ops.bevel(
        bm,
        geom=[bm.edges[i] for i in (1, 3, 6, 9)],
        loop_slide=True,
        affect='EDGES',
        profile=0.5, # round
        offset=corner_radius * 2,
        segments=corner_segments,
        )
      
bm.to_mesh(me)