"""Square and rectangular hollow section (cold-formed structural tube), EN 10219-2, any size, wall and length. Section: outside `width` (X) by `height` (Y) with wall thickness `wall`, centred on the origin, extruded along +Z by `length`. Corner radii as EN 10219-2 uses them for the sectional properties of its tables: outside ro and inside ri = 2.0T / 1.0T for T <= 6 mm, 2.5T / 1.5T for 6 < T <= 10 mm, 3.0T / 2.0T for T > 10 mm; or sharp corners (`corners = "sharp"`), the generic light tubes as step.parts' published models draw them (see the README). """ from steve import Model width = 40 # mm Outside width B height = 40 # mm Outside height H wall = 3 # mm Wall thickness T length = 1000 # mm Length material = "steel-s355" # Material corners = "en-10219" # Corners: en-10219 (EN 10219-2 radii) or sharp # material choice: (STEVE material library id, appearance colour) MATERIALS = { "steel-s355": ("steel-s355j2g3", "#7d8085"), # EN 10219-1 S355J2H (closest library grade S355J2G3) "steel-s235": ("steel-s235jr", "#7d8085"), # EN 10219-1 S235JRH "stainless-304": ("stainless-304", "#c9ccd0"), # EN 10088 1.4301 "unspecified": (None, "#9a9da2"), # the generic tubes' models name no material } # EN 10219-2:2006 Annex B clause B.3 (https://icdn.tradew.com/file/201801/1572618/pdf/6800507.pdf) corner radii for the sectional properties: (up to wall thickness T, ro / T, ri / T) CORNERS = [(6.0, 2.0, 1.0), (10.0, 2.5, 1.5), (1000.0, 3.0, 2.0)] ro_factor, ri_factor = next((o, i) for limit, o, i in CORNERS if wall <= limit) ro = ro_factor * wall if corners == "en-10219" else 0.0 ri = ri_factor * wall if corners == "en-10219" else 0.0 material_id, colour = MATERIALS[material] def rounded_rectangle(sk, id, w, h, r): """A w x h rectangle centred on the origin with corner radius r: four lines and four quarter arcs (r = 0: sharp).""" x, y = w / 2, h / 2 if r == 0: sk.rect(id, (-x, -y), (x, y)) return sk.line(f"{id}_bottom", (-x + r, -y), (x - r, -y)) sk.arc(f"{id}_corner1", (x - r, -y + r), r, 270, 360) sk.line(f"{id}_right", (x, -y + r), (x, y - r)) sk.arc(f"{id}_corner2", (x - r, y - r), r, 0, 90) sk.line(f"{id}_top", (x - r, y), (-x + r, y)) sk.arc(f"{id}_corner3", (-x + r, y - r), r, 90, 180) sk.line(f"{id}_left", (-x, y - r), (-x, -y + r)) sk.arc(f"{id}_corner4", (-x + r, -y + r), r, 180, 270) model = Model() with model.sketch("section", on="XY", name="Section") as sk: rounded_rectangle(sk, "outside", width, height, ro) rounded_rectangle(sk, "inside", width - 2 * wall, height - 2 * wall, ri) model.extrude("tube", "section", distance=length, name="Tube") if material_id: # "unspecified": no material assigned model.material(material_id, color=colour) result = model.result()