Previously: `|> hole(circle(radius = 2, center = p), %)` Now: `|> subtract2d(tool = circle(radius = 2, center = p))`
		
			
				
	
	
		
			167 lines
		
	
	
		
			540 KiB
		
	
	
	
		
			Markdown
		
	
	
	
	
	
			
		
		
	
	
			167 lines
		
	
	
		
			540 KiB
		
	
	
	
		
			Markdown
		
	
	
	
	
	
---
 | 
						|
title: "translate"
 | 
						|
excerpt: "Move a solid or a sketch."
 | 
						|
layout: manual
 | 
						|
---
 | 
						|
 | 
						|
Move a solid or a sketch.
 | 
						|
 | 
						|
This is really useful for assembling parts together. You can create a part and then move it to the correct location.
 | 
						|
 | 
						|
Translate is really useful for sketches if you want to move a sketch and then rotate it using the `rotate` function to create a loft.
 | 
						|
 | 
						|
```js
 | 
						|
translate(
 | 
						|
  objects: SolidOrSketchOrImportedGeometry,
 | 
						|
  x?: number,
 | 
						|
  y?: number,
 | 
						|
  z?: number,
 | 
						|
  global?: bool,
 | 
						|
): SolidOrSketchOrImportedGeometry
 | 
						|
```
 | 
						|
 | 
						|
 | 
						|
### Arguments
 | 
						|
 | 
						|
| Name | Type | Description | Required |
 | 
						|
|----------|------|-------------|----------|
 | 
						|
| `objects` | [`SolidOrSketchOrImportedGeometry`](/docs/kcl/types/SolidOrSketchOrImportedGeometry) | The solid, sketch, or set of solids or sketches to move. | Yes |
 | 
						|
| `x` | [`number`](/docs/kcl/types/number) | The amount to move the solid or sketch along the x axis. Defaults to 0 if not provided. | No |
 | 
						|
| `y` | [`number`](/docs/kcl/types/number) | The amount to move the solid or sketch along the y axis. Defaults to 0 if not provided. | No |
 | 
						|
| `z` | [`number`](/docs/kcl/types/number) | The amount to move the solid or sketch along the z axis. Defaults to 0 if not provided. | No |
 | 
						|
| `global` | [`bool`](/docs/kcl/types/bool) | If true, the transform is applied in global space. The origin of the model will move. By default, the transform is applied in local sketch axis, therefore the origin will not move. | No |
 | 
						|
 | 
						|
### Returns
 | 
						|
 | 
						|
[`SolidOrSketchOrImportedGeometry`](/docs/kcl/types/SolidOrSketchOrImportedGeometry) - Data for a solid, sketch, or an imported geometry.
 | 
						|
 | 
						|
 | 
						|
### Examples
 | 
						|
 | 
						|
```js
 | 
						|
// Move a pipe.
 | 
						|
 | 
						|
// Create a path for the sweep.
 | 
						|
sweepPath = startSketchOn(XZ)
 | 
						|
  |> startProfile(at = [0.05, 0.05])
 | 
						|
  |> line(end = [0, 7])
 | 
						|
  |> tangentialArc(angle = 90, radius = 5)
 | 
						|
  |> line(end = [-3, 0])
 | 
						|
  |> tangentialArc(angle = -90, radius = 5)
 | 
						|
  |> line(end = [0, 7])
 | 
						|
 | 
						|
// Create a hole for the pipe.
 | 
						|
pipeHole = startSketchOn(XY)
 | 
						|
  |> circle(center = [0, 0], radius = 1.5)
 | 
						|
 | 
						|
sweepSketch = startSketchOn(XY)
 | 
						|
  |> circle(center = [0, 0], radius = 2)
 | 
						|
  |> subtract2d(tool = pipeHole)
 | 
						|
  |> sweep(path = sweepPath)
 | 
						|
  |> translate(x = 1.0, y = 1.0, z = 2.5)
 | 
						|
```
 | 
						|
 | 
						|

 | 
						|
 | 
						|
```js
 | 
						|
// Move an imported model.
 | 
						|
 | 
						|
 | 
						|
import "tests/inputs/cube.sldprt" as cube
 | 
						|
 | 
						|
// Circle so you actually see the move.
 | 
						|
startSketchOn(XY)
 | 
						|
  |> circle(center = [-10, -10], radius = 10)
 | 
						|
  |> extrude(length = 10)
 | 
						|
 | 
						|
cube
 | 
						|
  |> translate(x = 10.0, y = 10.0, z = 2.5)
 | 
						|
```
 | 
						|
 | 
						|

 | 
						|
 | 
						|
```js
 | 
						|
// Sweep two sketches along the same path.
 | 
						|
 | 
						|
 | 
						|
sketch001 = startSketchOn(XY)
 | 
						|
rectangleSketch = startProfile(sketch001, at = [-200, 23.86])
 | 
						|
  |> angledLine(angle = 0, length = 73.47, tag = $rectangleSegmentA001)
 | 
						|
  |> angledLine(angle = segAng(rectangleSegmentA001) - 90, length = 50.61)
 | 
						|
  |> angledLine(angle = segAng(rectangleSegmentA001), length = -segLen(rectangleSegmentA001))
 | 
						|
  |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
 | 
						|
  |> close()
 | 
						|
 | 
						|
circleSketch = circle(sketch001, center = [200, -30.29], radius = 32.63)
 | 
						|
 | 
						|
sketch002 = startSketchOn(YZ)
 | 
						|
sweepPath = startProfile(sketch002, at = [0, 0])
 | 
						|
  |> yLine(length = 231.81)
 | 
						|
  |> tangentialArc(radius = 80, angle = -90)
 | 
						|
  |> xLine(length = 384.93)
 | 
						|
 | 
						|
parts = sweep([rectangleSketch, circleSketch], path = sweepPath)
 | 
						|
 | 
						|
// Move the sweeps.
 | 
						|
translate(
 | 
						|
  parts,
 | 
						|
  x = 1.0,
 | 
						|
  y = 1.0,
 | 
						|
  z = 2.5,
 | 
						|
)
 | 
						|
```
 | 
						|
 | 
						|

 | 
						|
 | 
						|
```js
 | 
						|
// Move a sketch.
 | 
						|
 | 
						|
 | 
						|
fn square(length) {
 | 
						|
  l = length / 2
 | 
						|
  p0 = [-l, -l]
 | 
						|
  p1 = [-l, l]
 | 
						|
  p2 = [l, l]
 | 
						|
  p3 = [l, -l]
 | 
						|
 | 
						|
  return startSketchOn(XY)
 | 
						|
    |> startProfile(at = p0)
 | 
						|
    |> line(endAbsolute = p1)
 | 
						|
    |> line(endAbsolute = p2)
 | 
						|
    |> line(endAbsolute = p3)
 | 
						|
    |> close()
 | 
						|
}
 | 
						|
 | 
						|
square(10)
 | 
						|
  |> translate(x = 5, y = 5)
 | 
						|
  |> extrude(length = 10)
 | 
						|
```
 | 
						|
 | 
						|

 | 
						|
 | 
						|
```js
 | 
						|
// Translate and rotate a sketch to create a loft.
 | 
						|
sketch001 = startSketchOn(XY)
 | 
						|
 | 
						|
fn square() {
 | 
						|
  return startProfile(sketch001, at = [-10, 10])
 | 
						|
    |> xLine(length = 20)
 | 
						|
    |> yLine(length = -20)
 | 
						|
    |> xLine(length = -20)
 | 
						|
    |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
 | 
						|
    |> close()
 | 
						|
}
 | 
						|
 | 
						|
profile001 = square()
 | 
						|
 | 
						|
profile002 = square()
 | 
						|
  |> translate(z = 20)
 | 
						|
  |> rotate(axis = [0, 0, 1.0], angle = 45)
 | 
						|
 | 
						|
loft([profile001, profile002])
 | 
						|
```
 | 
						|
 | 
						|

 | 
						|
 | 
						|
 |