MCPcopy
hub / github.com/CadQuery/cadquery / testLegoBrick

Method testLegoBrick

tests/test_cadquery.py:1485–1533  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1483 self.assertTupleAlmostEquals((v.X, v.Y), (10 + 50, 20), 3)
1484
1485 def testLegoBrick(self):
1486 # test making a simple lego brick
1487 # which of the below
1488
1489 # inputs
1490 lbumps = 8
1491 wbumps = 2
1492
1493 # lego brick constants
1494 P = 8.0 # nominal pitch
1495 c = 0.1 # clearance on each brick side
1496 H = 1.2 * P # nominal height of a brick
1497 bumpDiam = 4.8 # the standard bump diameter
1498 # the nominal thickness of the walls, normally 1.5
1499 t = (P - (2 * c) - bumpDiam) / 2.0
1500
1501 postDiam = P - t # works out to 6.5
1502 total_length = lbumps * P - 2.0 * c
1503 total_width = wbumps * P - 2.0 * c
1504
1505 # build the brick
1506 s = Workplane("XY").box(total_length, total_width, H) # make the base
1507 s = s.faces("<Z").shell(-1.0 * t) # shell inwards not outwards
1508 s = (
1509 s.faces(">Z")
1510 .workplane()
1511 .rarray(P, P, lbumps, wbumps, True)
1512 .circle(bumpDiam / 2.0)
1513 .extrude(1.8)
1514 ) # make the bumps on the top
1515
1516 # add posts on the bottom. posts are different diameter depending on geometry
1517 # solid studs for 1 bump, tubes for multiple, none for 1x1
1518 # this is cheating a little-- how to select the inner face from the shell?
1519 tmp = s.faces("<Z").workplane(invert=True)
1520
1521 if lbumps > 1 and wbumps > 1:
1522 tmp = (
1523 tmp.rarray(P, P, lbumps - 1, wbumps - 1, center=True)
1524 .circle(postDiam / 2.0)
1525 .circle(bumpDiam / 2.0)
1526 .extrude(H - t)
1527 )
1528 elif lbumps > 1:
1529 tmp = tmp.rarray(P, P, lbumps - 1, 1, center=True).circle(t).extrude(H - t)
1530 elif wbumps > 1:
1531 tmp = tmp.rarray(P, P, 1, wbumps - 1, center=True).circle(t).extrude(H - t)
1532
1533 self.saveModel(s)
1534
1535 def testAngledHoles(self):
1536 s = (

Callers

nothing calls this directly

Calls 9

saveModelMethod · 0.95
WorkplaneClass · 0.85
boxMethod · 0.80
extrudeMethod · 0.80
workplaneMethod · 0.80
shellMethod · 0.45
facesMethod · 0.45
circleMethod · 0.45
rarrayMethod · 0.45

Tested by

no test coverage detected