Files
modeling-app/public/kcl-samples/enclosure/main.kcl
Adam Chalmers 89bae66257 KCL: User-defined KCL functions in examples etc now use keywords (#6603)
Preparing for the removal of positional functions from the language. The first big step is to change all our KCL code examples, test code, public samples etc to all use keyword functions.

Apologies for how large this PR is. Most of it is:

- Changing example KCL that defined its own functions, so the functions now use keyword arguments rather than positional arguments. E.g. change `cube([20, 20])` to be `cube(center = [20, 20])`.
- Some parts of the code assumed positional code and didn't handle keyword calls, e.g. the linter would only check for positional calls to startSketchOn. Now they should work with either positional or keyword.
- Update all the artifacts

This does _not_ remove support for positional calls. That will be in a follow-up PR.
2025-05-01 12:36:51 -04:00

169 lines
5.5 KiB
Plaintext

// Enclosure
// An enclosure body and sealing lid for storing items
// Set units
@settings(defaultLengthUnit = mm)
// Define parameters
length = 175
width = 125
height = 70
wallThickness = 3
holeDia = 4
// Model a box with base enclosure dimensions
sketch001 = startSketchOn(XY)
|> startProfile(at = [0, 0])
|> angledLine(angle = 0, length = width, tag = $rectangleSegmentA001)
|> angledLine(angle = segAng(rectangleSegmentA001) + 90, length = length, tag = $rectangleSegmentB001)
|> angledLine(angle = segAng(rectangleSegmentA001), length = -segLen(rectangleSegmentA001), tag = $rectangleSegmentC001)
|> line(endAbsolute = [profileStartX(%), profileStartY(%)], tag = $rectangleSegmentD001)
|> close()
extrude001 = extrude(sketch001, length = height)
|> fillet(
radius = wallThickness * 4,
tags = [
getNextAdjacentEdge(rectangleSegmentA001),
getNextAdjacentEdge(rectangleSegmentB001),
getNextAdjacentEdge(rectangleSegmentC001),
getNextAdjacentEdge(rectangleSegmentD001)
],
)
// Apply a shell to the enclosure base to create the internal storage
|> shell(faces = [END], thickness = wallThickness)
// Define a function to create the internal structure to secure a fastener at each corner
fn function001(@originStart) {
// Create a plane to sketch on shell interior
plane001 = {
origin = [0.0, 0.0, wallThickness],
xAxis = [1.0, 0.0, 0.0],
yAxis = [0.0, 1.0, 0.0],
zAxis = [0.0, 0.0, 1.0]
}
// Create a pillar with a fasterner hole at the center
sketch002 = startSketchOn(plane001)
|> circle(center = [originStart[0], originStart[1]], radius = holeDia + wallThickness)
|> subtract2d(tool = circle(center = [originStart[0], originStart[1]], radius = holeDia))
extrude002 = extrude(sketch002, length = height - wallThickness)
return extrude002
}
// Place the internal pillar at each corner
function001([
wallThickness * 3 + holeDia,
wallThickness * 3 + holeDia
])
function001([
wallThickness * 3 + holeDia,
length - (wallThickness * 3 + holeDia)
])
function001([
width - (wallThickness * 3 + holeDia),
wallThickness * 3 + holeDia
])
function001([
width - (wallThickness * 3 + holeDia),
length - (wallThickness * 3 + holeDia)
])
// Define lid position and outer surface
sketch003 = startSketchOn(XY)
|> startProfile(at = [width * 1.2, 0])
|> angledLine(angle = 0, length = width, tag = $rectangleSegmentA002)
|> angledLine(angle = segAng(rectangleSegmentA001) + 90, length = length, tag = $rectangleSegmentB002)
|> angledLine(angle = segAng(rectangleSegmentA001), length = -segLen(rectangleSegmentA001), tag = $rectangleSegmentC002)
|> line(endAbsolute = [profileStartX(%), profileStartY(%)], tag = $rectangleSegmentD002)
|> close()
|> subtract2d(tool = circle(
center = [
width * 1.2 + wallThickness * 3 + holeDia,
wallThickness * 3 + holeDia
],
radius = holeDia,
))
|> subtract2d(tool = circle(
center = [
width * 1.2 + wallThickness * 3 + holeDia,
length - (wallThickness * 3 + holeDia)
],
radius = holeDia,
))
|> subtract2d(tool = circle(
center = [
width * 2.2 - (wallThickness * 3 + holeDia),
wallThickness * 3 + holeDia
],
radius = holeDia,
))
|> subtract2d(tool = circle(
center = [
width * 2.2 - (wallThickness * 3 + holeDia),
length - (wallThickness * 3 + holeDia)
],
radius = holeDia,
))
extrude003 = extrude(sketch003, length = wallThickness)
|> fillet(
radius = wallThickness * 4,
tags = [
getNextAdjacentEdge(rectangleSegmentA002),
getNextAdjacentEdge(rectangleSegmentB002),
getNextAdjacentEdge(rectangleSegmentC002),
getNextAdjacentEdge(rectangleSegmentD002)
],
)
// Define lid inner and sealing surfaces
sketch004 = startSketchOn(extrude003, face = END)
|> startProfile(at = [
width * 1.2 + wallThickness,
wallThickness
])
|> angledLine(angle = 0, length = width - (2 * wallThickness), tag = $rectangleSegmentA003)
|> angledLine(angle = segAng(rectangleSegmentA003) + 90, length = length - (2 * wallThickness), tag = $rectangleSegmentB003)
|> angledLine(angle = segAng(rectangleSegmentA003), length = -segLen(rectangleSegmentA003), tag = $rectangleSegmentC003)
|> line(endAbsolute = [profileStartX(%), profileStartY(%)], tag = $rectangleSegmentD003)
|> close()
|> subtract2d(tool = circle(
center = [
width * 1.2 + wallThickness * 3 + holeDia,
wallThickness * 3 + holeDia
],
radius = holeDia + wallThickness,
))
|> subtract2d(tool = circle(
center = [
width * 1.2 + wallThickness * 3 + holeDia,
length - (wallThickness * 3 + holeDia)
],
radius = holeDia + wallThickness,
))
|> subtract2d(tool = circle(
center = [
width * 2.2 - (wallThickness * 3 + holeDia),
wallThickness * 3 + holeDia
],
radius = holeDia + wallThickness,
))
|> subtract2d(tool = circle(
center = [
width * 2.2 - (wallThickness * 3 + holeDia),
length - (wallThickness * 3 + holeDia)
],
radius = holeDia + wallThickness,
))
extrude004 = extrude(sketch004, length = wallThickness)
|> fillet(
radius = wallThickness * 3,
tags = [
getNextAdjacentEdge(rectangleSegmentA003),
getNextAdjacentEdge(rectangleSegmentB003),
getNextAdjacentEdge(rectangleSegmentC003),
getNextAdjacentEdge(rectangleSegmentD003)
],
)