kcl-samples → parametric-shelf-unit
parametric-shelf-unit

KCL
// Parametric Shelf Unit
// A modular and adjustable 3D shelf model designed for basic furniture design.
// This model includes:
// - Two vertical side panels (left and right)
// - A floor base (spacer) at the bottom
// - Multiple evenly spaced horizontal shelf boards
// - Optional top board acting as a cover
// All elements are parametric and adaptable through clearly named variables.
@settings(defaultLengthUnit = m, kclVersion = 1.0)
// --- Global Dimensions ---
unitWidth = 1 // overall external width of the shelf
unitHeight = 2 // total height including top and base
unitDepth = 0.4 // depth from front to back
shelfBoardCount = 5 // number of usable shelf boards (excludes top cover)
// --- Panel & Shelf Geometry ---
panelThickness = 0.02 // thickness of side panels and shelf boards
sidePanelOffset = unitWidth - panelThickness // distance between origin points of left and right panel
// --- Base Spacer (Plinth) ---
baseHeight = 0.05 // elevation of bottom plinth from ground
baseInset = 0.03 // inward offset at the front (toe kick for foot clearance)
baseWidth = unitWidth - (panelThickness * 2) // internal width of base element
baseDepth = unitDepth - baseInset // shallower depth than full unit
// --- Shelf Placement ---
shelfStartZ = baseHeight // Z elevation of the first shelf board
shelfThickness = panelThickness // shelf board thickness
shelfWidth = baseWidth // width same as base
shelfDepth = unitDepth // full shelf depth
totalShelfBoards = shelfBoardCount + 1 // includes top cover board
availableVerticalSpace = unitHeight - baseHeight - shelfThickness
shelfSpacing = availableVerticalSpace / shelfBoardCount // vertical distance between shelf boards
// --- Reference Plane ---
basePlane = startSketchOn(XY)
// --- Side Panels ---
// Left and right vertical structural walls.
sidePanelProfile = startProfile(basePlane, at = [-unitWidth / 2, 0])
|> yLine(length = -unitDepth)
|> xLine(length = panelThickness)
|> yLine(length = unitDepth)
|> close()
|> patternLinear2d(
%,
instances = 2,
distance = sidePanelOffset,
axis = [1, 0],
)
sidePanels = extrude(sidePanelProfile, length = unitHeight)
// --- Floor Base / Plinth ---
// Supporting base element between side panels.
baseProfile = startProfile(basePlane, at = [-baseWidth / 2, 0])
|> yLine(length = -baseDepth)
|> xLine(length = baseWidth)
|> yLine(length = baseDepth)
|> close()
baseBlock = extrude(baseProfile, length = baseHeight)
// --- First Shelf Board ---
firstShelfPlane = offsetPlane(XY, offset = shelfStartZ)
firstShelfSketch = startSketchOn(firstShelfPlane)
firstShelfProfile = startProfile(firstShelfSketch, at = [-shelfWidth / 2, 0])
|> yLine(length = -shelfDepth)
|> xLine(length = shelfWidth)
|> yLine(length = shelfDepth)
|> close()
firstShelf = extrude(firstShelfProfile, length = shelfThickness)
// --- Shelf Stack ---
shelves = patternLinear3d(
firstShelf,
instances = totalShelfBoards,
distance = shelfSpacing,
axis = [0, 0, 1],
)