Files
modeling-app/docs/kcl/subtract.md
Jess Frazelle 35844842de Bump modeling api & pull thru csg endpoints (#6245)
* csg-upts

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

* base

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

* do the id shit

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

* tried to run

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

* csg-upts

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

* use bens samples

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

* use bens samples

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

* gen std

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

* gen std

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

* updates

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

* updates

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

* fix;

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

---------

Signed-off-by: Jess Frazelle <github@jessfraz.com>
2025-04-10 18:30:57 -07:00

161 KiB

title, excerpt, layout
title excerpt layout
subtract Subtract removes tool solids from base solids, leaving the remaining material. manual

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.

subtract(
  solids: [Solid],
  tools: [Solid],
  tolerance?: number,
): [Solid]

Arguments

Name Type Description Required
solids [Solid] The solids to use as the base to subtract from. Yes
tools [Solid] The solids to subtract. Yes
tolerance number The tolerance to use for the subtraction operation. No

Returns

[Solid]

Examples

// Subtract a cylinder from a cube using the stdlib functions.


fn cube(center, size) {
  return startSketchOn(XY)
    |> startProfileAt([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)

subtractedPart = subtract([part001], tools = [part002])

Rendered example of subtract 0

// 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, size) {
  return startSketchOn(XY)
    |> startProfileAt([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: subtract([part001], tools=[part002])
subtractedPart = part001 - part002

Rendered example of subtract 1