0
$\begingroup$

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?

enter image description here

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

$\endgroup$
3
  • 1
    $\begingroup$ i think you know how to create the cube and how to use the bevel. modifier -> you see the commands in the console. All you need is the selection of the edges in python, so combine this with that answer here: blender.stackexchange.com/questions/182182/… $\endgroup$
    – Chris
    Commented Mar 13, 2021 at 9:11
  • $\begingroup$ An easy way might be to create a plane, collect all the vertices and bevel them, then collect all the vertices again and extrude. $\endgroup$
    – Psyonic
    Commented Mar 13, 2021 at 9:58
  • $\begingroup$ @batFINGER i feel really honored that master batFINGER concurs me ;) – $\endgroup$
    – Chris
    Commented Mar 13, 2021 at 11:33

1 Answer 1

2
$\begingroup$

BMesh script.

enter image description here "Spam tin" 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(...)

enter image description here

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 > 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)
$\endgroup$

You must log in to answer this question.

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