-
Notifications
You must be signed in to change notification settings - Fork 0
/
pipe-flange-assembly.kcl
282 lines (258 loc) · 7.24 KB
/
pipe-flange-assembly.kcl
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
// Pipe and Flange Assembly
// A crucial component in various piping systems, designed to facilitate the connection, disconnection, and access to piping for inspection, cleaning, and modifications. This assembly combines pipes (long cylindrical conduits) with flanges (plate-like fittings) to create a secure yet detachable joint.
flangeThickness = .125
flangeBaseDia = 2
boreHeight = 1
flangePipeDia = 1
mountingHoleDia = 0.425
screwDia = 0.375
tol = 0.010
hexNutScale = 0.90
wallThickness = 0.5
screwLength = 1.125
washerThickness = 0.0625
screwStart = [
0,
flangeThickness + washerThickness,
1.375
]
capRatio = .190 / .313 // Ratio grabbed from another screw
hexRatio = 5 / 32 / .190 // Ratio grabbed from another screw
hexStartingAngle = 210 // first angle of hex pattern (degrees)
hexInteriorAngle = 120 // degrees
hexChangeAngle = 180 - hexInteriorAngle // degrees
screwPlane = {
plane: {
origin: {
x: screwStart[0],
y: screwStart[1],
z: screwStart[2]
},
xAxis: { x: 1, y: 0, z: 0 },
yAxis: { x: 0, y: 0, z: 1 },
zAxis: { x: 0, y: 1, z: 0 }
}
}
fn capScrew = (start, length, dia) => {
headLength = dia // inch
wallToWallLength = hexRatio * dia
headDia = dia / capRatio
hexWallLength = wallToWallLength / 2 * 1 / cos(toRadians(30)) // inch
// Length of Cap Head is always equal to diameter
capHeadLength = dia
// Create the head of the cap screw
screwHeadSketch = startSketchOn(screwPlane)
|> circle({ center: [0, 0], radius: headDia / 2 }, %)
// Extrude the screw head sketch
screwHead = extrude(dia, screwHeadSketch)
// Define the sketch of the hex pattern on the screw head
hexPatternSketch = startSketchOn(screwHead, 'end')
|> startProfileAt([
-start[0] + wallToWallLength / 2,
start[2]
], %)
|> yLine(-hexWallLength / 2, %)
|> angledLine({
angle: hexStartingAngle,
length: hexWallLength
}, %)
|> angledLine({
angle: hexStartingAngle - hexChangeAngle,
length: hexWallLength
}, %)
|> angledLine({
angle: hexStartingAngle - (2 * hexChangeAngle),
length: hexWallLength
}, %)
|> angledLine({
angle: hexStartingAngle - (3 * hexChangeAngle),
length: hexWallLength
}, %)
|> angledLine({
angle: hexStartingAngle - (4 * hexChangeAngle),
length: hexWallLength
}, %)
|> close(%)
hexPattern = extrude(-headLength * 0.75, hexPatternSketch)
return hexPattern
}
workingPlane = {
plane: {
origin: { x: 0, y: flangeThickness, z: 0 },
xAxis: { x: 0, y: 0, z: 1 },
yAxis: { x: 1, y: 0, z: 0 },
zAxis: { x: 0, y: 1, z: 0 }
}
}
// Washer function
fn washer = (plane, start, thk, innerDia, outerDia) => {
washerSketch = startSketchOn(plane)
|> circle({
center: [start[0], start[1]],
radius: outerDia / 2
}, %)
|> hole(circle({
center: [start[0], start[1]],
radius: innerDia / 2
}, %), %)
|> extrude(thk, %)
return washerSketch
}
// Hex nut function
fn hexNut = (start, thk, innerDia) => {
hexNutSketch = startSketchOn({
plane: {
origin: {
x: start[0],
y: -wallThickness - washerThickness,
z: start[2]
},
xAxis: { x: 1, y: 0, z: 0 },
yAxis: { x: 0, y: 0, z: 1 },
zAxis: { x: 0, y: 1, z: 0 }
}
})
|> startProfileAt([0 + innerDia * hexNutScale, 0], %)
|> angledLine({
angle: 240,
length: innerDia * hexNutScale
}, %)
|> angledLine({
angle: 180,
length: innerDia * hexNutScale
}, %)
|> angledLine({
angle: 120,
length: innerDia * hexNutScale
}, %)
|> angledLine({
angle: 60,
length: innerDia * hexNutScale
}, %)
|> angledLine({ angle: 0, length: innerDia * .90 }, %)
|> close(%)
|> hole(circle({ center: [0, 0], radius: innerDia / 2 }, %), %)
|> extrude(-thk, %)
return hexNutSketch
}
// Mounting holes pattern
mountingHolePattern = startSketchOn('XZ')
|> circle({
center: [screwStart[0], screwStart[2]],
radius: screwDia / 2 + tol
}, %)
|> patternCircular2d({
arcDegrees: 360,
center: [0, 0],
instances: 7,
rotateDuplicates: true
}, %)
// Sketch and revolve the pipe
pipe = startSketchOn('XY')
|> startProfileAt([flangePipeDia / 2 - tol, 0], %)
|> line([0, -2], %)
|> angledLine({ angle: -60, length: .5 }, %)
|> line([0, -1], %)
|> line([-flangeThickness, 0], %)
|> line([0, 1], %)
|> angledLine({ angle: -240, length: .5 }, %)
|> line([0, 5], %)
|> angledLine({ angle: 60, length: .5 }, %)
|> line([0, 1], %)
|> line([flangeThickness, 0], %)
|> line([0, -1], %)
|> angledLine({ angle: 240, length: .5 }, %)
|> close(%)
|> revolve({ axis: 'y' }, %)
// Sketch and extrude the wall
wall = startSketchOn('XZ')
|> startProfileAt([-4, -4], %)
|> line([0, 8], %)
|> line([8, 0], %)
|> line([0, -8], %)
|> close(%)
|> hole(mountingHolePattern, %)
|> hole(circle({
center: [0, 0],
radius: flangePipeDia / 2
}, %), %)
|> extrude(wallThickness, %)
// Sketch and revolve the flange
flangeBase = startSketchOn('XZ')
|> circle({
center: [0, 0],
radius: flangeBaseDia
}, %)
|> hole(mountingHolePattern, %)
|> hole(circle({
center: [0, 0],
radius: flangePipeDia / 2
}, %), %)
|> extrude(-flangeThickness, %)
// Create the washer and pattern around the flange
washer(workingPlane, [screwStart[2], screwStart[0]], 0.0625, screwDia + tol, 0.625)
|> patternCircular3d({
axis: [0, 1, 0],
center: [0, 0, 0],
instances: 7,
arcDegrees: 360,
rotateDuplicates: true
}, %)
// Create the cap screw and pattern around the flange
capScrew([
0,
flangeThickness + washerThickness,
1.375
], screwLength, screwDia)
|> patternCircular3d({
axis: [0, 1, 0],
center: [0, 0, 0],
instances: 7,
arcDegrees: 360,
rotateDuplicates: true
}, %)
screwBodySketch = startSketchOn(screwPlane)
|> circle({ center: [0, 0], radius: screwDia / 2 }, %)
screwBody = extrude(-screwLength, screwBodySketch)
|> patternCircular3d({
axis: [0, 1, 0],
center: [0, 0, 0],
instances: 7,
arcDegrees: 360,
rotateDuplicates: true
}, %)
// Create a plane for the washers on the back side of the wall
backSideWasherPlane = {
plane: {
origin: {
x: 0,
y: -wallThickness - washerThickness,
z: 0
},
xAxis: { x: 0, y: 0, z: 1 },
yAxis: { x: 1, y: 0, z: 0 },
zAxis: { x: 0, y: 1, z: 0 }
}
}
// Create the washers on the backside of the wall
washer(backSideWasherPlane, [screwStart[2], screwStart[0]], 0.0625, screwDia + tol, 0.625)
|> patternCircular3d({
axis: [0, 1, 0],
center: [0, 0, 0],
instances: 7,
arcDegrees: 360,
rotateDuplicates: true
}, %)
// Create the hex nut and pattern around the flange
hexNut([
screwStart[0],
screwStart[1],
screwStart[2]
], .25, screwDia + tol)
|> patternCircular3d({
axis: [0, 1, 0],
center: [0, 0, 0],
instances: 7,
arcDegrees: 360,
rotateDuplicates: true
}, %)