0

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

DrDress
  • 563
  • 4
  • 19
  • 1
    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: https://blender.stackexchange.com/questions/182182/how-to-select-with-python-code-only-vertical-edges-from-cube – Chris Mar 13 '21 at 09:11
  • An easy way might be to create a plane, collect all the vertices and bevel them, then collect all the vertices again and extrude. – Psyonic Mar 13 '21 at 09:58
  • @batFINGER i feel really honored that master batFINGER concurs me ;) – – Chris Mar 13 '21 at 11:33

1 Answers1

2

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)

batFINGER
  • 84,216
  • 10
  • 108
  • 233