108 lines
246 KiB
Markdown
108 lines
246 KiB
Markdown
---
|
|
title: "union"
|
|
subtitle: "Function in std::solid"
|
|
excerpt: "Union two or more solids into a single solid."
|
|
layout: manual
|
|
---
|
|
|
|
Union two or more solids into a single solid.
|
|
|
|
```kcl
|
|
union(
|
|
@solids: [Solid; 2+],
|
|
tolerance?: number(Length),
|
|
): [Solid; 1+]
|
|
```
|
|
|
|
|
|
|
|
### Arguments
|
|
|
|
| Name | Type | Description | Required |
|
|
|----------|------|-------------|----------|
|
|
| `solids` | `[Solid; 2+]` | The solids to union. | Yes |
|
|
| `tolerance` | [`number(Length)`](/docs/kcl-std/types/std-types-number) | The tolerance to use for the union operation. | No |
|
|
|
|
### Returns
|
|
|
|
[`[Solid; 1+]`](/docs/kcl-std/types/std-types-Solid)
|
|
|
|
|
|
### Examples
|
|
|
|
```kcl
|
|
// 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(center = [0, 0], size = 10)
|
|
part002 = cube(center = [7, 3], size = 5)
|
|
|> translate(z = 1)
|
|
|
|
unionedPart = union([part001, part002])
|
|
```
|
|
|
|

|
|
|
|
```kcl
|
|
// 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(center = [0, 0], size = 10)
|
|
part002 = cube(center = [7, 3], size = 5)
|
|
|> translate(z = 1)
|
|
|
|
// This is the equivalent of: union([part001, part002])
|
|
unionedPart = part001 + part002
|
|
```
|
|
|
|

|
|
|
|
```kcl
|
|
// 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(center = [0, 0], size = 10)
|
|
part002 = cube(center = [7, 3], size = 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
|
|
```
|
|
|
|

|
|
|
|
|