Files
modeling-app/docs/kcl/union.md
Nick Cameron c050739f41 Some improvements to the boxed signatures in the docs (#6593)
* Show a more reasonable name in function docs

Signed-off-by: Nick Cameron <nrc@ncameron.org>

* Fix buggy docs for union types

Signed-off-by: Nick Cameron <nrc@ncameron.org>

* Make types in the docs signatures into links

Signed-off-by: Nick Cameron <nrc@ncameron.org>

---------

Signed-off-by: Nick Cameron <nrc@ncameron.org>
2025-04-30 16:03:22 +00:00

246 KiB

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

Union two or more solids into a single solid.

union(
  solids: [[[Solid](/docs/kcl/types/Solid)]](/docs/kcl/types/[Solid](/docs/kcl/types/Solid)),
  tolerance?: [number](/docs/kcl/types/number),
): [[[Solid](/docs/kcl/types/Solid)]](/docs/kcl/types/[Solid](/docs/kcl/types/Solid))

Arguments

Name Type Description Required
solids [Solid] The solids to union. Yes
tolerance number The tolerance to use for the union operation. No

Returns

[Solid]

Examples

// Union two cubes using the stdlib functions.


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

part001 = cube([0, 0], 10)
part002 = cube([7, 3], 5)
  |> translate(z = 1)

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, size) {
  return startSketchOn(XY)
    |> startProfile(at = [center[0] - size, center[1] - size])
    |> line(endAbsolute = [center[0] + size, center[1] - size])
    |> line(endAbsolute = [center[0] + size, center[1] + size])
    |> line(endAbsolute = [center[0] - size, center[1] + size])
    |> close()
    |> extrude(length = 10)
}

part001 = cube([0, 0], 10)
part002 = cube([7, 3], 5)
  |> translate(z = 1)

// 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, size) {
  return startSketchOn(XY)
    |> startProfile(at = [center[0] - size, center[1] - size])
    |> line(endAbsolute = [center[0] + size, center[1] - size])
    |> line(endAbsolute = [center[0] + size, center[1] + size])
    |> line(endAbsolute = [center[0] - size, center[1] + size])
    |> close()
    |> extrude(length = 10)
}

part001 = cube([0, 0], 10)
part002 = cube([7, 3], 5)
  |> translate(z = 1)

  // 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