- Notifications
You must be signed in to change notification settings - Fork 322
/
Copy pathEx100_Lego_Brick.py
70 lines (61 loc) · 1.6 KB
/
Ex100_Lego_Brick.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# This script can create any regular rectangular Lego(TM) Brick
importcadqueryascq
#####
# Inputs
######
lbumps=1# number of bumps long
wbumps=1# number of bumps wide
thin=True# True for thin, False for thick
#
# Lego Brick Constants-- these make a lego brick a lego :)
#
pitch=8.0
clearance=0.1
bumpDiam=4.8
bumpHeight=1.8
ifthin:
height=3.2
else:
height=9.6
t= (pitch- (2*clearance) -bumpDiam) /2.0
postDiam=pitch-t# works out to 6.5
total_length=lbumps*pitch-2.0*clearance
total_width=wbumps*pitch-2.0*clearance
# make the base
s=cq.Workplane("XY").box(total_length, total_width, height)
# shell inwards not outwards
s=s.faces("<Z").shell(-1.0*t)
# make the bumps on the top
s= (
s.faces(">Z")
.workplane()
.rarray(pitch, pitch, lbumps, wbumps, True)
.circle(bumpDiam/2.0)
.extrude(bumpHeight)
)
# add posts on the bottom. posts are different diameter depending on geometry
# solid studs for 1 bump, tubes for multiple, none for 1x1
tmp=s.faces("<Z").workplane(invert=True)
iflbumps>1andwbumps>1:
tmp= (
tmp.rarray(pitch, pitch, lbumps-1, wbumps-1, center=True)
.circle(postDiam/2.0)
.circle(bumpDiam/2.0)
.extrude(height-t)
)
eliflbumps>1:
tmp= (
tmp.rarray(pitch, pitch, lbumps-1, 1, center=True)
.circle(t)
.extrude(height-t)
)
elifwbumps>1:
tmp= (
tmp.rarray(pitch, pitch, 1, wbumps-1, center=True)
.circle(t)
.extrude(height-t)
)
else:
tmp=s
# Render the solid
show_object(tmp)