Class Body

class cadscript.Body(workplane: Workplane)[source]

Represents a 3D CAD object. They are typically created using make_* functions, e.g. cadscript.make_box() or cadscript.make_extrude().

fillet(edgesStr: str, amount: float) Body[source]

Fillets the specified edges of the body.

Parameters:
  • edgesStr (str) – The edges to fillet.

  • amount (float) – The radius of the fillet.

Returns:

The modified body object.

Return type:

Body

chamfer(edgesStr: str, amount: float) Body[source]

Chamfers the specified edges of the body.

Parameters:
  • edgesStr (str) – The edges to chamfer.

  • amount (float) – The distance of the chamfer.

Returns:

The modified body object.

Return type:

Body

move(translationVector: Tuple[float, float, float]) Body[source]

Moves the body by the specified translation vector.

Parameters:

translationVector (Vector3DType) – The translation vector.

Returns:

The modified body object.

Return type:

Body

rotate(axis: Literal['X', 'Y', 'Z'], degrees: float) Body[source]

Rotates the body around the specified axis by the specified angle in degrees.

Parameters:
  • axis (AxisType) – The axis to rotate around. Can be one of “X”, “Y” or “Z”.

  • degrees (float) – The angle in degrees.

Returns:

The modified body object.

Return type:

Body

cut(tool_body: Body) Body[source]

Performs a boolean cut operation with another body.

Parameters:

tool_body (Body) – The body to cut from this body.

add(tool_body: Body) Body[source]

Performs a boolean add operation with another body.

Parameters:

tool_body (Body) – The body to add to this body.

Returns:

The modified body object.

Return type:

Body

intersect(tool_body: Body) Body[source]

Performs a boolean intersect operation with another body.

Parameters:

tool_body (Body) – The body to intersect with this body.

Returns:

The modified body object.

Return type:

Body

add_extrude(faceStr: str, sketch: Sketch, amount: float) Body[source]

Adds an extrusion to the specified face of the body using a sketch.

Parameters:
  • faceStr (str) – The face to extrude.

  • sketch (Sketch) – The sketch to extrude.

  • amount (float) – The amount of extrusion.

Returns:

The modified body object.

Return type:

Body

cut_extrude(faceStr: str, sketch: Sketch, amount: float) Body[source]

Adds a cut extrusion to the specified face of the body using a sketch.

Parameters:
  • faceStr (str) – The face to extrude.

  • sketch (Sketch) – The sketch to extrude.

  • amount (float) – The amount of extrusion. For cutting you usually want to use a negative value to cut into the body.

Returns:

The modified body object.

Return type:

Body

make_extrude(faceStr: str, sketch: Sketch, amount: float) Body[source]

Creates a new body by extruding the specified face of the body using a sketch.

Parameters:
  • faceStr (str) – The face to extrude.

  • sketch (Sketch) – The sketch to extrude.

  • amount (float) – The amount of extrusion.

Returns:

The newly created body object.

Return type:

Body

Note

This function is different from add_extrude() in that it creates a new body instead of modifying the existing one.

cut_hole(faceStr: str, *, r: float | None = None, radius: float | None = None, d: float | None = None, diameter: float | None = None, depth: float | None = None, positions: Tuple[float, float] | Iterable[Tuple[float, float]] | None = None, pos: Tuple[float, float] | Iterable[Tuple[float, float]] | None = None, countersink_angle: float | None = None, counterbore_depth: float | None = None, r2: float | None = None, radius2: float | None = None, d2: float | None = None, diameter2: float | None = None) Body[source]

Cuts a hole into the body. It can be a regular hole, a countersink hole or a counterbore hole. For all types of holes, you can specify the diameter of the hole using one of the r, radius, d or diameter parameters. To create a countersink hole, specify the countersink_angle parameter and also give the diameter of the countersink using one of the r2, radius2, d2 or diameter2 parameters. To create a counterbore hole, specify the counterbore_depth parameter. Specify the counterbore by giving the diameter of the counterbore using one of the r2, radius2, d2 or diameter2 parameters and the depth of the counterbore using the counterbore_depth parameter.

Parameters:
  • faceStr (str) – The face to cut the hole into.

  • r (Optional[float]) – The radius of the hole.

  • radius (Optional[float]) – The radius of the hole (alternative to ‘r’).

  • d (Optional[float]) – The diameter of the hole.

  • diameter (Optional[float]) – The diameter of the hole (alternative to ‘d’).

  • depth (Optional[float]) – The depth of the hole. If not specified, the hole will go through the entire body.

  • positions (Optional[Union[Vector2DType, Iterable[Vector2DType]]]) – If given, a hole is cut for each of the entries, specifying the center as (x,y) tuple. If None, a single hole will be cut at the origin.

  • pos (Optional[Union[Vector2DType, Iterable[Vector2DType]]]) – Shorthand for positions parameter, only use one of them.

  • countersink_angle (Optional[float]) – The angle of the countersink. A typical value is 90 or 82 degrees.

  • counterbore_depth (Optional[float]) – The depth of the counterbore.

  • r2 (Optional[float]) – The radius of the countersink or counterbore.

  • radius2 (Optional[float]) – The radius of the countersink or counterbore (alternative to ‘r2’).

  • d2 (Optional[float]) – The diameter of the countersink or counterbore.

  • diameter2 (Optional[float]) – The diameter of the countersink or counterbore (alternative to ‘d2’).

get_center() Tuple[float, float, float][source]

Returns the center of the bounding box of the body.

Returns:

The center of the bounding box.

Return type:

Vector3DType

get_extent() Interval3D[source]

Returns the extent of the bounding box of the body.

Returns:

The extent of the bounding box.

Return type:

Interval3D

center(center: Literal['X', 'Y', 'Z', 'XY', 'XZ', 'YZ', 'XYZ'] | bool = True) Body[source]

Centers the body at the origin.

Parameters:

center (CenterDefinitionType, optional) – Whether to center the object. If False, the object will be not moved Can also be “X”, “Y” or “Z” to center in only one direction or “XY”, “XZ”, “YZ” to center in two directions. The other directions will be unchanged. Defaults to True which centers the box in all directions.

move_to_origin(axis: Literal['X', 'Y', 'Z', 'XY', 'XZ', 'YZ', 'XYZ'] | bool = True) Body[source]

Moves the body to the origin, i.e. that the lower corner of the bounding box is at the origin.

Parameters:

axis (CenterDefinitionType, optional) – Can be “X”, “Y” or “Z” to move the object in only one direction or “XY”, “XZ”, “YZ” to move it in two directions. The other directions will be unchanged. Defaults to True which moves the body in all directions. If False, the object will be not moved at all.

mirror(axis: Literal['X', 'Y', 'Z'], copy_and_merge: bool = True) Body[source]

Mirrors the body.

Parameters:
  • axis (AxisType) – The axis to mirror the object along.

  • copy_and_merge (bool, optional) – If True, the body is mirrored and merged with the original body. If False, the original sketch is replaced by the mirrored body. Defaults to True.

Returns:

The mirrored body object.

Return type:

Sketch

export_step(filename: str) None[source]

Exports the body to a STEP file.

Parameters:

filename (str) – The filename to export to.

export_stl(filename: str) None[source]

Exports the body to an STL file.

Parameters:

filename (str) – The filename to export to.

render_svg(filename: str) None[source]

Renders the body as an SVG illustration.

Parameters:

filename (str) – The filename to export to.

copy() Body[source]

Creates a copy of the body.

Returns:

The newly created body object.

Return type:

Body

cq() Workplane[source]

Returns the underlying CadQuery workplane object. Useful when mixing CadQuery and Cadscript code.

Returns:

The underlying CadQuery workplane object.

Return type:

cq.Workplane