kcl-samples → hex-nut

hex-nut

hex-nut

KCL

// Hex nut
// A hex nut is a type of fastener with a threaded hole and a hexagonal outer shape, used in a wide variety of applications to secure parts together. The hexagonal shape allows for a greater torque to be applied with wrenches or tools, making it one of the most common nut types in hardware. 


// Define constants (5/16" - 24 thread size)
const wallToWallLength = 0.5 // inches
const thickness = 0.266 // inches
const diameter = 0.3125 // inches

// Define a function for the hex nut
fn hexNut = (start, thk, innerDia) => {
  const hexNutSketch = startSketchOn('-XZ')
  |> startProfileAt([start[0] + innerDia, start[1]], %)
  |> angledLine({
       angle: 240,
       length: innerDia
     }, %)
  |> angledLine({
       angle: 180,
       length: innerDia
     }, %)
  |> angledLine({
       angle: 120,
       length: innerDia
     }, %)
  |> angledLine({
       angle: 60,
       length: innerDia
     }, %)
  |> angledLine({ angle: 0, length: innerDia * .90 }, %)
  |> close(%)
  |> hole(circle([start[0], start[1]], innerDia / 2, %), %)
  |> extrude(thk, %)
  return hexNutSketch
}

// Create a hex nut
hexNut([0, 0], thickness, diameter)