Skip to content

Commit 3e8bb44

Browse files
committed
TooTallToby tutorials: unbreak and test.
- Unbreak the three broken tutorials (fixes gumyr#848) - This involved a rewrite of PPP-01-10 because I already had my own solution to that one and I couldn't easily tell what was going wrong with the previous solution. - Add assertions to all the tutorials so that non-raising means success - Add the TTT examples to `test_examples.py` added recently for gumyr#909 - Also added sympy to development dependencies since one of the TTT examples uses it.
1 parent 1c9cd01 commit 3e8bb44

15 files changed

+576
-486
lines changed

docs/assets/ttt/ttt-23-02-02-sm_hanger.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,13 @@
9292
mirror(about=Plane.YZ)
9393
mirror(about=Plane.XZ)
9494

95-
print(f"Mass: {sm_hanger.part.volume*7800*1e-6:0.1f} g")
95+
got_mass = sm_hanger.part.volume*7800*1e-6
96+
want_mass = 1028
97+
tolerance = 10
98+
delta = abs(got_mass - want_mass)
99+
print(f"Mass: {got_mass:0.1f} g")
100+
assert delta < tolerance, f'{got_mass=}, {want_mass=}, {delta=}, {tolerance=}'
101+
102+
assert abs(got_mass - 1028) < 10, f'{got_mass=}, want=1028, tolerance=10'
96103

97104
show(sm_hanger)

docs/assets/ttt/ttt-23-t-24-curved_support.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
(yl8 - 50) / (55 / 2 - xl8) - tan(radians(8)), # 8 degree slope
2828
]
2929
# There are two solutions but we want the 2nd one
30-
solution = sympy.solve(equations, dict=True)[1]
30+
solution = {k: float(v) for k,v in sympy.solve(equations, dict=True)[1].items()}
3131

3232
# Create the critical points
3333
c30 = Vector(x30, solution[y30])
@@ -58,5 +58,11 @@
5858
with Locations((0, 125)):
5959
Hole(20 / 2)
6060

61-
print(curved_support.part.volume * 7800e-6)
61+
got_mass = curved_support.part.volume * 7800e-6
62+
want_mass = 1294
63+
delta = abs(got_mass - want_mass)
64+
tolerance = 3
65+
print(f"Mass: {got_mass:0.1f} g")
66+
assert delta < tolerance, f'{got_mass=}, {want_mass=}, {delta=}, {tolerance=}'
67+
6268
show(curved_support)

docs/assets/ttt/ttt-24-SPO-06-Buffer_Stand.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@
4545
mirror(about=Plane.YZ)
4646

4747
part = scale(p.part, IN)
48-
print(f"\npart weight = {part.volume*7800e-6/LB:0.2f} lbs")
48+
49+
50+
got_mass = part.volume*7800e-6/LB
51+
want_mass = 3.923
52+
tolerance = 0.02
53+
delta = abs(got_mass - want_mass)
54+
print(f"Mass: {got_mass:0.1f} lbs")
55+
assert delta < tolerance, f'{got_mass=}, {want_mass=}, {delta=}, {tolerance=}'
4956

5057
show(p)

docs/assets/ttt/ttt-ppp0101.py

Lines changed: 54 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,54 @@
1-
"""
2-
Too Tall Toby Party Pack 01-01 Bearing Bracket
3-
"""
4-
5-
from build123d import *
6-
from ocp_vscode import *
7-
8-
densa = 7800 / 1e6 # carbon steel density g/mm^3
9-
densb = 2700 / 1e6 # aluminum alloy
10-
densc = 1020 / 1e6 # ABS
11-
12-
with BuildPart() as p:
13-
with BuildSketch() as s:
14-
Rectangle(115, 50)
15-
with Locations((5 / 2, 0)):
16-
SlotOverall(90, 12, mode=Mode.SUBTRACT)
17-
extrude(amount=15)
18-
19-
with BuildSketch(Plane.XZ.offset(50 / 2)) as s3:
20-
with Locations((-115 / 2 + 26, 15)):
21-
SlotOverall(42 + 2 * 26 + 12, 2 * 26, rotation=90)
22-
zz = extrude(amount=-12)
23-
split(bisect_by=Plane.XY)
24-
edgs = p.part.edges().filter_by(Axis.Y).group_by(Axis.X)[-2]
25-
fillet(edgs, 9)
26-
27-
with Locations(zz.faces().sort_by(Axis.Y)[0]):
28-
with Locations((42 / 2 + 6, 0)):
29-
CounterBoreHole(24 / 2, 34 / 2, 4)
30-
mirror(about=Plane.XZ)
31-
32-
with BuildSketch() as s4:
33-
RectangleRounded(115, 50, 6)
34-
extrude(amount=80, mode=Mode.INTERSECT)
35-
# fillet does not work right, mode intersect is safer
36-
37-
with BuildSketch(Plane.YZ) as s4:
38-
with BuildLine() as bl:
39-
l1 = Line((0, 0), (18 / 2, 0))
40-
l2 = PolarLine(l1 @ 1, 8, 60, length_mode=LengthMode.VERTICAL)
41-
l3 = Line(l2 @ 1, (0, 8))
42-
mirror(about=Plane.YZ)
43-
make_face()
44-
extrude(amount=115/2, both=True, mode=Mode.SUBTRACT)
45-
46-
show_object(p)
47-
print(f"\npart mass = {p.part.volume*densa:0.2f}")
1+
"""
2+
Too Tall Toby Party Pack 01-01 Bearing Bracket
3+
"""
4+
5+
from build123d import *
6+
from ocp_vscode import *
7+
8+
densa = 7800 / 1e6 # carbon steel density g/mm^3
9+
densb = 2700 / 1e6 # aluminum alloy
10+
densc = 1020 / 1e6 # ABS
11+
12+
with BuildPart() as p:
13+
with BuildSketch() as s:
14+
Rectangle(115, 50)
15+
with Locations((5 / 2, 0)):
16+
SlotOverall(90, 12, mode=Mode.SUBTRACT)
17+
extrude(amount=15)
18+
19+
with BuildSketch(Plane.XZ.offset(50 / 2)) as s3:
20+
with Locations((-115 / 2 + 26, 15)):
21+
SlotOverall(42 + 2 * 26 + 12, 2 * 26, rotation=90)
22+
zz = extrude(amount=-12)
23+
split(bisect_by=Plane.XY)
24+
edgs = p.part.edges().filter_by(Axis.Y).group_by(Axis.X)[-2]
25+
fillet(edgs, 9)
26+
27+
with Locations(zz.faces().sort_by(Axis.Y)[0]):
28+
with Locations((42 / 2 + 6, 0)):
29+
CounterBoreHole(24 / 2, 34 / 2, 4)
30+
mirror(about=Plane.XZ)
31+
32+
with BuildSketch() as s4:
33+
RectangleRounded(115, 50, 6)
34+
extrude(amount=80, mode=Mode.INTERSECT)
35+
# fillet does not work right, mode intersect is safer
36+
37+
with BuildSketch(Plane.YZ) as s4:
38+
with BuildLine() as bl:
39+
l1 = Line((0, 0), (18 / 2, 0))
40+
l2 = PolarLine(l1 @ 1, 8, 60, length_mode=LengthMode.VERTICAL)
41+
l3 = Line(l2 @ 1, (0, 8))
42+
mirror(about=Plane.YZ)
43+
make_face()
44+
extrude(amount=115/2, both=True, mode=Mode.SUBTRACT)
45+
46+
show_object(p)
47+
48+
49+
got_mass = p.part.volume*densa
50+
want_mass = 797.15
51+
tolerance = 1
52+
delta = abs(got_mass - want_mass)
53+
print(f"Mass: {got_mass:0.2f} g")
54+
assert delta < tolerance, f'{got_mass=}, {want_mass=}, {delta=}, {tolerance=}'

docs/assets/ttt/ttt-ppp0102.py

Lines changed: 57 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,57 @@
1-
"""
2-
Too Tall Toby Party Pack 01-02 Post Cap
3-
"""
4-
5-
from build123d import *
6-
from ocp_vscode import *
7-
8-
densa = 7800 / 1e6 # carbon steel density g/mm^3
9-
densb = 2700 / 1e6 # aluminum alloy
10-
densc = 1020 / 1e6 # ABS
11-
12-
13-
# TTT Party Pack 01: PPP0102, mass(abs) = 43.09g
14-
with BuildPart() as p:
15-
with BuildSketch(Plane.XZ) as sk1:
16-
Rectangle(49, 48 - 8, align=(Align.CENTER, Align.MIN))
17-
Rectangle(9, 48, align=(Align.CENTER, Align.MIN))
18-
with Locations((9 / 2, 40)):
19-
Ellipse(20, 8)
20-
split(bisect_by=Plane.YZ)
21-
revolve(axis=Axis.Z)
22-
23-
with BuildSketch(Plane.YZ.offset(-15)) as xc1:
24-
with Locations((0, 40 / 2 - 17)):
25-
Ellipse(10 / 2, 4 / 2)
26-
with BuildLine(Plane.XZ) as l1:
27-
CenterArc((-15, 40 / 2), 17, 90, 180)
28-
sweep(path=l1)
29-
30-
fillet(p.edges().filter_by(GeomType.CIRCLE, reverse=True).group_by(Axis.X)[0], 1)
31-
32-
with BuildLine(mode=Mode.PRIVATE) as lc1:
33-
PolarLine(
34-
(42 / 2, 0), 37, 94, length_mode=LengthMode.VERTICAL
35-
) # construction line
36-
37-
pts = [
38-
(0, 0),
39-
(42 / 2, 0),
40-
((lc1.line @ 1).X, (lc1.line @ 1).Y),
41-
(0, (lc1.line @ 1).Y),
42-
]
43-
with BuildSketch(Plane.XZ) as sk2:
44-
Polygon(*pts, align=None)
45-
fillet(sk2.vertices().group_by(Axis.X)[1], 3)
46-
revolve(axis=Axis.Z, mode=Mode.SUBTRACT)
47-
48-
show(p)
49-
print(f"\npart mass = {p.part.volume*densa:0.2f}")
1+
"""
2+
Too Tall Toby Party Pack 01-02 Post Cap
3+
"""
4+
5+
from build123d import *
6+
from ocp_vscode import *
7+
8+
densa = 7800 / 1e6 # carbon steel density g/mm^3
9+
densb = 2700 / 1e6 # aluminum alloy
10+
densc = 1020 / 1e6 # ABS
11+
12+
13+
# TTT Party Pack 01: PPP0102, mass(abs) = 43.09g
14+
with BuildPart() as p:
15+
with BuildSketch(Plane.XZ) as sk1:
16+
Rectangle(49, 48 - 8, align=(Align.CENTER, Align.MIN))
17+
Rectangle(9, 48, align=(Align.CENTER, Align.MIN))
18+
with Locations((9 / 2, 40)):
19+
Ellipse(20, 8)
20+
split(bisect_by=Plane.YZ)
21+
revolve(axis=Axis.Z)
22+
23+
with BuildSketch(Plane.YZ.offset(-15)) as xc1:
24+
with Locations((0, 40 / 2 - 17)):
25+
Ellipse(10 / 2, 4 / 2)
26+
with BuildLine(Plane.XZ) as l1:
27+
CenterArc((-15, 40 / 2), 17, 90, 180)
28+
sweep(path=l1)
29+
30+
fillet(p.edges().filter_by(GeomType.CIRCLE, reverse=True).group_by(Axis.X)[0], 1)
31+
32+
with BuildLine(mode=Mode.PRIVATE) as lc1:
33+
PolarLine(
34+
(42 / 2, 0), 37, 94, length_mode=LengthMode.VERTICAL
35+
) # construction line
36+
37+
pts = [
38+
(0, 0),
39+
(42 / 2, 0),
40+
((lc1.line @ 1).X, (lc1.line @ 1).Y),
41+
(0, (lc1.line @ 1).Y),
42+
]
43+
with BuildSketch(Plane.XZ) as sk2:
44+
Polygon(*pts, align=None)
45+
fillet(sk2.vertices().group_by(Axis.X)[1], 3)
46+
revolve(axis=Axis.Z, mode=Mode.SUBTRACT)
47+
48+
show(p)
49+
50+
51+
got_mass = p.part.volume*densc
52+
want_mass = 43.09
53+
tolerance = 1
54+
delta = abs(got_mass - want_mass)
55+
print(f"Mass: {got_mass:0.2f} g")
56+
assert delta < tolerance, f'{got_mass=}, {want_mass=}, {delta=}, {tolerance=}'
57+

docs/assets/ttt/ttt-ppp0103.py

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,40 @@
1-
"""
2-
Too Tall Toby Party Pack 01-03 C Clamp Base
3-
"""
4-
5-
from build123d import *
6-
from ocp_vscode import *
7-
8-
densa = 7800 / 1e6 # carbon steel density g/mm^3
9-
densb = 2700 / 1e6 # aluminum alloy
10-
densc = 1020 / 1e6 # ABS
11-
12-
13-
with BuildPart() as ppp0103:
14-
with BuildSketch() as sk1:
15-
RectangleRounded(34 * 2, 95, 18)
16-
with Locations((0, -2)):
17-
RectangleRounded((34 - 16) * 2, 95 - 18 - 14, 7, mode=Mode.SUBTRACT)
18-
with Locations((-34 / 2, 0)):
19-
Rectangle(34, 95, 0, mode=Mode.SUBTRACT)
20-
extrude(amount=16)
21-
with BuildSketch(Plane.XZ.offset(-95 / 2)) as cyl1:
22-
with Locations((0, 16 / 2)):
23-
Circle(16 / 2)
24-
extrude(amount=18)
25-
with BuildSketch(Plane.XZ.offset(95 / 2 - 14)) as cyl2:
26-
with Locations((0, 16 / 2)):
27-
Circle(16 / 2)
28-
extrude(amount=23)
29-
with Locations(Plane.XZ.offset(95 / 2 + 9)):
30-
with Locations((0, 16 / 2)):
31-
CounterSinkHole(5.5 / 2, 11.2 / 2, None, 90)
32-
33-
show(ppp0103)
34-
print(f"\npart mass = {ppp0103.part.volume*densb:0.2f}")
1+
"""
2+
Too Tall Toby Party Pack 01-03 C Clamp Base
3+
"""
4+
5+
from build123d import *
6+
from ocp_vscode import *
7+
8+
densa = 7800 / 1e6 # carbon steel density g/mm^3
9+
densb = 2700 / 1e6 # aluminum alloy
10+
densc = 1020 / 1e6 # ABS
11+
12+
13+
with BuildPart() as ppp0103:
14+
with BuildSketch() as sk1:
15+
RectangleRounded(34 * 2, 95, 18)
16+
with Locations((0, -2)):
17+
RectangleRounded((34 - 16) * 2, 95 - 18 - 14, 7, mode=Mode.SUBTRACT)
18+
with Locations((-34 / 2, 0)):
19+
Rectangle(34, 95, 0, mode=Mode.SUBTRACT)
20+
extrude(amount=16)
21+
with BuildSketch(Plane.XZ.offset(-95 / 2)) as cyl1:
22+
with Locations((0, 16 / 2)):
23+
Circle(16 / 2)
24+
extrude(amount=18)
25+
with BuildSketch(Plane.XZ.offset(95 / 2 - 14)) as cyl2:
26+
with Locations((0, 16 / 2)):
27+
Circle(16 / 2)
28+
extrude(amount=23)
29+
with Locations(Plane.XZ.offset(95 / 2 + 9)):
30+
with Locations((0, 16 / 2)):
31+
CounterSinkHole(5.5 / 2, 11.2 / 2, None, 90)
32+
33+
show(ppp0103)
34+
35+
got_mass = ppp0103.part.volume*densb
36+
want_mass = 96.13
37+
tolerance = 1
38+
delta = abs(got_mass - want_mass)
39+
print(f"Mass: {got_mass:0.2f} g")
40+
assert delta < tolerance, f'{got_mass=}, {want_mass=}, {delta=}, {tolerance=}'

0 commit comments

Comments
 (0)