kcl-samples → flange-xy

flange-xy

flange-xy

KCL

// Flange with XY coordinates
// 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 in inches (in)
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 flange base and the six mounting holes
flangeBase = startSketchOn('XY')
  |> circle({
       center = [0, 0],
       radius = baseDia / 2
     }, %)
  |> hole(circle({
       center = [mountingHolePlacementDiameter / 2, 0],
       radius = mountingHoleDia / 2
     }, %), %)
  |> hole(circle({
       center = [0, mountingHolePlacementDiameter / 2],
       radius = mountingHoleDia / 2
     }, %), %)
  |> hole(circle({
       center = [-mountingHolePlacementDiameter / 2, 0],
       radius = mountingHoleDia / 2
     }, %), %)
  |> hole(circle({
       center = [0, -mountingHolePlacementDiameter / 2],
       radius = mountingHoleDia / 2
     }, %), %)
  |> 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, 'end')
  |> 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, %)

// https://www.mcmaster.com/44685K193/