291 lines
1.0 MiB
291 lines
1.0 MiB
---
|
|
title: "clone"
|
|
subtitle: "Function in std"
|
|
excerpt: "Clone a sketch or solid."
|
|
layout: manual
|
|
---
|
|
|
|
Clone a sketch or solid.
|
|
|
|
```kcl
|
|
// Clone a basic sketch and move it and extrude it.
|
|
exampleSketch = startSketchOn(XY)
|
|
|> startProfile(at = [0, 0])
|
|
|> line(end = [10, 0])
|
|
|> line(end = [0, 10])
|
|
|> line(end = [-10, 0])
|
|
|> close()
|
|
|
|
clonedSketch = clone(exampleSketch)
|
|
|> scale(x = 1.0, y = 1.0, z = 2.5)
|
|
|> translate(x = 15.0, y = 0, z = 0)
|
|
|> extrude(length = 5)
|
|
|
|
```
|
|
|
|
### Arguments
|
|
|
|
| Name | Type | Description | Required |
|
|
|----------|------|-------------|----------|
|
|
| `geometry` | [`Sketch`](/docs/kcl-std/types/std-types-Sketch) or [`Solid`](/docs/kcl-std/types/std-types-Solid) or [`ImportedGeometry`](/docs/kcl-std/types/std-types-ImportedGeometry) | The sketch, solid, or imported geometry to be cloned. | Yes |
|
|
|
|
### Returns
|
|
|
|
[`Sketch`](/docs/kcl-std/types/std-types-Sketch) or [`Solid`](/docs/kcl-std/types/std-types-Solid) or [`ImportedGeometry`](/docs/kcl-std/types/std-types-ImportedGeometry)
|
|
|
|
### Description
|
|
|
|
This works essentially like a copy-paste operation. It creates a perfect replica
|
|
at that point in time that you can manipulate individually afterwards.
|
|
|
|
This doesn't really have much utility unless you need the equivalent of a double
|
|
instance pattern with zero transformations.
|
|
|
|
Really only use this function if YOU ARE SURE you need it. In most cases you
|
|
do not need clone and using a pattern with `instance = 2` is more appropriate.
|
|
|
|
### Function signature
|
|
|
|
```kcl
|
|
clone(@geometry: Sketch | Solid | ImportedGeometry): Sketch | Solid | ImportedGeometry
|
|
```
|
|
|
|
### Examples
|
|
|
|
```kcl
|
|
// Clone a basic sketch and move it and extrude it.
|
|
exampleSketch = startSketchOn(XY)
|
|
|> startProfile(at = [0, 0])
|
|
|> line(end = [10, 0])
|
|
|> line(end = [0, 10])
|
|
|> line(end = [-10, 0])
|
|
|> close()
|
|
|
|
clonedSketch = clone(exampleSketch)
|
|
|> scale(x = 1.0, y = 1.0, z = 2.5)
|
|
|> translate(x = 15.0, y = 0, z = 0)
|
|
|> extrude(length = 5)
|
|
|
|
```
|
|
|
|

|
|
|
|
```kcl
|
|
// Clone a basic solid and move it.
|
|
|
|
|
|
exampleSketch = startSketchOn(XY)
|
|
|> startProfile(at = [0, 0])
|
|
|> line(end = [10, 0])
|
|
|> line(end = [0, 10])
|
|
|> line(end = [-10, 0])
|
|
|> close()
|
|
|
|
myPart = extrude(exampleSketch, length = 5)
|
|
clonedPart = clone(myPart)
|
|
|> translate(x = 25.0)
|
|
|
|
```
|
|
|
|

|
|
|
|
```kcl
|
|
// Translate and rotate a cloned sketch to create a loft.
|
|
|
|
|
|
sketch001 = startSketchOn(XY)
|
|
|> startProfile(at = [-10, 10])
|
|
|> xLine(length = 20)
|
|
|> yLine(length = -20)
|
|
|> xLine(length = -20)
|
|
|> close()
|
|
|
|
sketch002 = clone(sketch001)
|
|
|> translate(x = 0, y = 0, z = 20)
|
|
|> rotate(axis = [0, 0, 1.0], angle = 45)
|
|
|
|
loft([sketch001, sketch002])
|
|
|
|
```
|
|
|
|

|
|
|
|
```kcl
|
|
// Translate a cloned solid. Fillet only the clone.
|
|
|
|
|
|
sketch001 = startSketchOn(XY)
|
|
|> startProfile(at = [-10, 10])
|
|
|> xLine(length = 20)
|
|
|> yLine(length = -20)
|
|
|> xLine(length = -20, tag = $filletTag)
|
|
|> close()
|
|
|> extrude(length = 5)
|
|
|
|
sketch002 = clone(sketch001)
|
|
|> translate(x = 0, y = 0, z = 20)
|
|
|> fillet(radius = 2, tags = [getNextAdjacentEdge(filletTag)])
|
|
|
|
```
|
|
|
|

|
|
|
|
```kcl
|
|
// You can reuse the tags from the original geometry with the cloned geometry.
|
|
|
|
|
|
sketch001 = startSketchOn(XY)
|
|
|> startProfile(at = [0, 0])
|
|
|> line(end = [10, 0])
|
|
|> line(end = [0, 10], tag = $sketchingFace)
|
|
|> line(end = [-10, 0])
|
|
|> close()
|
|
|
|
sketch002 = clone(sketch001)
|
|
|> translate(x = 10, y = 20, z = 0)
|
|
|> extrude(length = 5)
|
|
|
|
startSketchOn(sketch002, face = sketchingFace)
|
|
|> startProfile(at = [1, 1])
|
|
|> line(end = [8, 0])
|
|
|> line(end = [0, 8])
|
|
|> line(end = [-8, 0])
|
|
|> close(tag = $sketchingFace002)
|
|
|> extrude(length = 10)
|
|
|
|
```
|
|
|
|

|
|
|
|
```kcl
|
|
// You can also use the tags from the original geometry to fillet the cloned geometry.
|
|
|
|
|
|
width = 20
|
|
length = 10
|
|
thickness = 1
|
|
filletRadius = 2
|
|
|
|
mountingPlateSketch = startSketchOn(XY)
|
|
|> startProfile(at = [-width / 2, -length / 2])
|
|
|> line(endAbsolute = [width / 2, -length / 2], tag = $edge1)
|
|
|> line(endAbsolute = [width / 2, length / 2], tag = $edge2)
|
|
|> line(endAbsolute = [-width / 2, length / 2], tag = $edge3)
|
|
|> close(tag = $edge4)
|
|
|
|
mountingPlate = extrude(mountingPlateSketch, length = thickness)
|
|
|
|
clonedMountingPlate = clone(mountingPlate)
|
|
|> fillet(
|
|
radius = filletRadius,
|
|
tags = [
|
|
getNextAdjacentEdge(edge1),
|
|
getNextAdjacentEdge(edge2),
|
|
getNextAdjacentEdge(edge3),
|
|
getNextAdjacentEdge(edge4)
|
|
],
|
|
)
|
|
|> translate(x = 0, y = 50, z = 0)
|
|
|
|
```
|
|
|
|

|
|
|
|
```kcl
|
|
// Create a spring by sweeping around a helix path from a cloned sketch.
|
|
|
|
// Create a helix around the Z axis.
|
|
helixPath = helix(
|
|
angleStart = 0,
|
|
ccw = true,
|
|
revolutions = 4,
|
|
length = 10,
|
|
radius = 5,
|
|
axis = Z,
|
|
)
|
|
|
|
springSketch = startSketchOn(XZ)
|
|
|> circle(center = [0, 0], radius = 1)
|
|
|
|
// Create a spring by sweeping around the helix path.
|
|
sweepedSpring = clone(springSketch)
|
|
|> translate(x = 5)
|
|
|> sweep(path = helixPath)
|
|
|
|
```
|
|
|
|

|
|
|
|
```kcl
|
|
// A donut shape from a cloned sketch.
|
|
sketch001 = startSketchOn(XY)
|
|
|> circle(center = [15, 0], radius = 5)
|
|
|
|
sketch002 = clone(sketch001)
|
|
|> translate(z = 30)
|
|
|> revolve(angle = 360, axis = Y)
|
|
|
|
```
|
|
|
|

|
|
|
|
```kcl
|
|
// Sketch on the end of a revolved face by tagging the end face.
|
|
// This shows the cloned geometry will have the same tags as the original geometry.
|
|
|
|
|
|
exampleSketch = startSketchOn(XY)
|
|
|> startProfile(at = [4, 12])
|
|
|> line(end = [2, 0])
|
|
|> line(end = [0, -6])
|
|
|> line(end = [4, -6])
|
|
|> line(end = [0, -6])
|
|
|> line(end = [-3.75, -4.5])
|
|
|> line(end = [0, -5.5])
|
|
|> line(end = [-2, 0])
|
|
|> close()
|
|
|
|
example001 = revolve(
|
|
exampleSketch,
|
|
axis = Y,
|
|
angle = 180,
|
|
tagEnd = $end01,
|
|
)
|
|
|
|
// example002 = clone(example001)
|
|
// |> translate(x = 0, y = 20, z = 0)
|
|
|
|
|
|
// Sketch on the cloned face.
|
|
// exampleSketch002 = startSketchOn(example002, face = end01)
|
|
// |> startProfile(at = [4.5, -5])
|
|
// |> line(end = [0, 5])
|
|
// |> line(end = [5, 0])
|
|
// |> line(end = [0, -5])
|
|
// |> close()
|
|
|
|
|
|
// example003 = extrude(exampleSketch002, length = 5)
|
|
|
|
```
|
|
|
|

|
|
|
|
```kcl
|
|
// Clone an imported model.
|
|
|
|
|
|
import "tests/inputs/cube.sldprt" as cube
|
|
|
|
myCube = cube
|
|
|
|
clonedCube = clone(myCube)
|
|
|> translate(x = 1020)
|
|
|> appearance(color = "#ff0000", metalness = 50, roughness = 50)
|
|
|
|
```
|
|
|
|

|
|
|
|
|