* 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>
87 lines
188 KiB
Markdown
87 lines
188 KiB
Markdown
---
|
|
title: "subtract"
|
|
excerpt: "Subtract removes tool solids from base solids, leaving the remaining material."
|
|
layout: manual
|
|
---
|
|
|
|
**WARNING:** This function is deprecated.
|
|
|
|
Subtract removes tool solids from base solids, leaving the remaining material.
|
|
|
|
Performs a boolean subtraction operation, removing the volume of one or more tool solids from one or more base solids. The result is a new solid representing the material that remains after all tool solids have been cut away. This function is essential for machining simulations, cavity creation, and complex multi-body part modeling.
|
|
|
|
```js
|
|
subtract(
|
|
solids: [Solid],
|
|
tools: [Solid],
|
|
): [Solid]
|
|
```
|
|
|
|
|
|
### Arguments
|
|
|
|
| Name | Type | Description | Required |
|
|
|----------|------|-------------|----------|
|
|
| `solids` | [`[Solid]`](/docs/kcl/types/Solid) | The solids to use as the base to subtract from. | Yes |
|
|
| `tools` | [`[Solid]`](/docs/kcl/types/Solid) | The solids to subtract. | Yes |
|
|
|
|
### Returns
|
|
|
|
[`[Solid]`](/docs/kcl/types/Solid)
|
|
|
|
|
|
### Examples
|
|
|
|
```js
|
|
// Subtract a cylinder from a cube 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 = startSketchOn(XY)
|
|
|> circle(center = [0, 0], radius = 2)
|
|
|> extrude(length = 10)
|
|
|
|
subtractedPart = subtract([part001], tools = [part002])
|
|
```
|
|
|
|

|
|
|
|
```js
|
|
// Subtract a cylinder from a cube 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 = startSketchOn(XY)
|
|
|> circle(center = [0, 0], radius = 2)
|
|
|> extrude(length = 10)
|
|
|
|
// This is the equivalent of: subtract([part001], tools=[part002])
|
|
subtractedPart = part001 - part002
|
|
```
|
|
|
|

|
|
|
|
|