-
Notifications
You must be signed in to change notification settings - Fork 0
/
flange-with-patterns.kcl
63 lines (56 loc) · 2.03 KB
/
flange-with-patterns.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
// Flange
// A flange is a flat rim, collar, or rib, typically forged or cast, that is used to strengthen an object, guide it, or attach it to another object. Flanges are known for their use in various applications, including piping, plumbing, and mechanical engineering, among others.
// Define constants
mountingHoleDia = .625
baseDia = 4.625
pipeDia = 1.25
thickness = .625
totalThickness = 0.813
topTotalDiameter = 2.313
bottomThickness = 0.06
bottomTotalDiameter = 2.5
mountingHolePlacementDiameter = 3.5
baseThickness = .625
topTotalThickness = totalThickness - (bottomThickness+baseThickness)
holeLocator = baseDia - 8
nHoles = 4
// Add assertion so nHoles are always greater than 1
assertGreaterThan(nHoles, 1, "nHoles must be greater than 1")
// Create the circular pattern for the mounting holes
circles = startSketchOn('XY')
|> circle({center: [mountingHolePlacementDiameter /2, 0], radius: mountingHoleDia / 2}, %)
|> patternCircular2d({
arcDegrees: 360,
center: [0, 0],
instances: nHoles,
rotateDuplicates: true
}, %)
// Create the base of the flange and add the mounting holes
flangeBase = startSketchOn('XY')
|> circle({center: [0, 0], radius: baseDia/2}, %)
|> hole(circles, %)
|> hole(circle({center: [0, 0], radius: pipeDia/2}, %), %)
|> extrude(baseThickness, %)
// Plane for top face
topFacePlane = {
plane: {
origin: {
x: 0,
y: 0,
z: baseThickness
},
xAxis: { x: 1, y: 0, z: 0 },
yAxis: { x: 0, y: 1, z: 0 },
zAxis: { x: 0, y: 0, z: 1 }
}
}
// Create the extrusion on the top of the flange base
topExtrusion = startSketchOn(topFacePlane)
|> circle({center: [0, 0], radius: topTotalDiameter/2}, %)
|> hole(circle({center: [0, 0], radius: pipeDia/2}, %), %)
|> extrude(topTotalThickness, %)
// Create the extrusion on the bottom of the flange base
bottomExtrusion = startSketchOn("XY")
|> circle({center: [0, 0], radius: bottomTotalDiameter/2}, %)
|> hole(circle({center: [0, 0], radius: pipeDia/2}, %), %)
|> extrude(-bottomThickness, %)