Files
modeling-app/docs/kcl/union.md
Jess Frazelle 1fe1cfb397 Syntax sugar booleans (+ and -) which is intuitive for MEs (#6124)
* updates

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* docs

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* docs

Signed-off-by: Jess Frazelle <github@jessfraz.com>

---------

Signed-off-by: Jess Frazelle <github@jessfraz.com>
2025-04-03 02:13:03 +00:00

250 KiB

title, excerpt, layout
title excerpt layout
union Union two or more solids into a single solid. manual

WARNING: This function is deprecated.

Union two or more solids into a single solid.

union(solids: [Solid]): [Solid]

Arguments

Name Type Description Required
solids [Solid] The solids to union. Yes

Returns

[Solid]

Examples

// Union two cubes using the stdlib functions.


fn cube(center) {
  return startSketchOn(XY)
    |> startProfileAt([center[0] - 10, center[1] - 10], %)
    |> line(endAbsolute = [center[0] + 10, center[1] - 10])
    |> line(endAbsolute = [center[0] + 10, center[1] + 10])
    |> line(endAbsolute = [center[0] - 10, center[1] + 10])
    |> close()
    |> extrude(length = 10)
}

part001 = cube([0, 0])
part002 = cube([20, 10])

unionedPart = union([part001, part002])

Rendered example of union 0

// Union two cubes using operators.
// NOTE: This will not work when using codemods through the UI.
// Codemods will generate the stdlib function call instead.


fn cube(center) {
  return startSketchOn(XY)
    |> startProfileAt([center[0] - 10, center[1] - 10], %)
    |> line(endAbsolute = [center[0] + 10, center[1] - 10])
    |> line(endAbsolute = [center[0] + 10, center[1] + 10])
    |> line(endAbsolute = [center[0] - 10, center[1] + 10])
    |> close()
    |> extrude(length = 10)
}

part001 = cube([0, 0])
part002 = cube([20, 10])

// This is the equivalent of: union([part001, part002])
unionedPart = part001 + part002

Rendered example of union 1

// Union two cubes using the more programmer-friendly operator.
// NOTE: This will not work when using codemods through the UI.
// Codemods will generate the stdlib function call instead.


fn cube(center) {
  return startSketchOn(XY)
    |> startProfileAt([center[0] - 10, center[1] - 10], %)
    |> line(endAbsolute = [center[0] + 10, center[1] - 10])
    |> line(endAbsolute = [center[0] + 10, center[1] + 10])
    |> line(endAbsolute = [center[0] - 10, center[1] + 10])
    |> close()
    |> extrude(length = 10)
}

part001 = cube([0, 0])
part002 = cube([20, 10])

// This is the equivalent of: union([part001, part002])
// Programmers will understand `|` as a union operation, but mechanical engineers
// will understand `+`, we made both work.
unionedPart = part001 | part002

Rendered example of union 2