Skip to content

Instantly share code, notes, and snippets.

@bendavis78
Created October 2, 2023 17:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bendavis78/9eaf04a377ee1bc5b08be99b0981da2b to your computer and use it in GitHub Desktop.
Save bendavis78/9eaf04a377ee1bc5b08be99b0981da2b to your computer and use it in GitHub Desktop.
Brick tutorial using 123d CAD library
from build123d import *
from ocp_vscode import *
C, MIN, MAX = Align.CENTER, Align.MIN, Align.MAX
pip_count = 6
brick_unit_size = 8
pip_height = 1.8
pip_diameter = 4.8
block_length = brick_unit_size * pip_count
block_width = 16
base_height = 9.6
block_height = base_height + pip_height
support_outer_diameter = 6.5
support_inner_diameter = 4.8
ridge_width = 0.6
ridge_depth = 0.3
wall_thickness = 1.2
# Basic perimiter
sketch = Sketch()
sketch += Rectangle(block_length, block_width)
sketch -= offset(sketch, -wall_thickness, kind=Kind.INTERSECTION)
# Grid pattern
h_grid = GridLocations(0, brick_unit_size, 1, 2)
v_grid = GridLocations(brick_unit_size, 0, pip_count, 1)
sketch += h_grid * Rectangle(block_length, ridge_width)
sketch += v_grid * Rectangle(ridge_width, block_width)
# Remove center to expose ridges
sketch -= Rectangle(
block_length - 2 * (wall_thickness + ridge_depth),
block_width - 2 * (wall_thickness + ridge_depth),
)
# Add hollow circles to center
circle = Circle(support_outer_diameter / 2) - Circle(support_inner_diameter / 2)
sketch += GridLocations(brick_unit_size, 0, pip_count-1, 1) * circle
# Extrude sketch
brick = extrude(sketch, base_height - wall_thickness)
# Add top
top_pos = Pos(0, 0, brick.vertices().group_by(Axis.Z)[-1].first.Z)
top = top_pos * Box(block_length, block_width, wall_thickness, align=(C, C, MIN))
brick += top
# Add pips
grid = GridLocations(brick_unit_size, brick_unit_size, pip_count, 2)
top_face = top.faces().sort_by(Axis.Z).last
pip = Plane(top_face) * Cylinder(radius=pip_diameter / 2, height=pip_height, align=(C, C, MIN))
pips = grid * pip
brick += pips
# Add text to pips
pip_top = pip.faces().sort_by(Axis.Z).last
text = Sketch() + Text("123D", 1, font_style=FontStyle.BOLD)
text = Plane(pip_top) * text
brick += grid * extrude(text, .2)
show(brick)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment