CadQuery Class Summary

This page documents all of the methods and functions of the CadQuery classes, organized alphabetically.

See also

For a listing organized by functional area, see the API Reference

Core Classes

Sketch(parent, locs, obj)

2D sketch.

Workplane(, obj=None))

Defines a coordinate system in space, in which 2D coordinates can be used.

Assembly([obj, loc, name, color, metadata])

Nested assembly of Workplane and Shape objects defining their relative positions.

Constraint

alias of ConstraintSpec

Topological Classes

Shape(obj)

Represents a shape in the system.

Vertex(obj[, forConstruction])

A Single Point in Space

Edge(obj)

A trimmed curve that represents the border of a face

cadquery.occ_impl.shapes.Mixin1D()

Wire(obj)

A series of connected, ordered Edges, that typically bounds a Face

Face(obj)

a bounded surface that represents part of the boundary of a solid

Shell(obj)

the outer boundary of a surface

cadquery.occ_impl.shapes.Mixin3D()

Solid(obj)

a single solid

Compound(obj)

a collection of disconnected solids

Geometry Classes

Vector()

Create a 3-dimensional vector

Matrix()

A 3d , 4x4 transformation matrix.

Plane(origin[, xDir, normal])

A 2D coordinate system in space

Location(t)

Location in 3D space.

Selector Classes

Selector()

Filters a list of objects.

NearestToPointSelector(pnt)

Selects object nearest the provided point.

BoxSelector(point0, point1[, boundingbox])

Selects objects inside the 3D box defined by 2 points.

BaseDirSelector(vector[, tolerance])

A selector that handles selection on the basis of a single direction vector.

ParallelDirSelector(vector[, tolerance])

Selects objects parallel with the provided direction.

DirectionSelector(vector[, tolerance])

Selects objects aligned with the provided direction.

PerpendicularDirSelector(vector[, tolerance])

Selects objects perpendicular with the provided direction.

TypeSelector(typeString)

Selects objects having the prescribed geometry type.

RadiusNthSelector(n[, directionMax, tolerance])

Select the object with the Nth radius.

CenterNthSelector(vector, n[, directionMax, ...])

Sorts objects into a list with order determined by the distance of their center projected onto the specified direction.

DirectionMinMaxSelector(vector[, ...])

Selects objects closest or farthest in the specified direction.

DirectionNthSelector(vector, n[, ...])

Filters for objects parallel (or normal) to the specified direction then returns the Nth one.

LengthNthSelector(n[, directionMax, tolerance])

Select the object(s) with the Nth length

AreaNthSelector(n[, directionMax, tolerance])

Selects the object(s) with Nth area

BinarySelector(left, right)

Base class for selectors that operates with two other selectors.

AndSelector(left, right)

Intersection selector.

SumSelector(left, right)

Union selector.

SubtractSelector(left, right)

Difference selector.

InverseSelector(selector)

Inverts the selection of given selector.

StringSyntaxSelector(selectorString)

Filter lists objects using a simple string syntax.

Class Details

class cadquery.Assembly(obj: Shape | Workplane | None = None, loc: Location | None = None, name: str | None = None, color: Color | None = None, metadata: Dict[str, Any] | None = None)[source]

Bases: object

Nested assembly of Workplane and Shape objects defining their relative positions.

Parameters:
__init__(obj: Shape | Workplane | None = None, loc: Location | None = None, name: str | None = None, color: Color | None = None, metadata: Dict[str, Any] | None = None)[source]

construct an assembly

Parameters:
  • obj (Shape | Workplane | None) – root object of the assembly (default: None)

  • loc (Location | None) – location of the root object (default: None, interpreted as identity transformation)

  • name (str | None) – unique name of the root object (default: None, resulting in an UUID being generated)

  • color (Color | None) – color of the added object (default: None)

  • metadata (Dict[str, Any] | None) – a store for user-defined metadata (default: None)

Returns:

An Assembly object.

To create an empty assembly use:

assy = Assembly(None)

To create one constraint a root object:

b = Workplane().box(1, 1, 1)
assy = Assembly(b, Location(Vector(0, 0, 1)), name="root")
__iter__(loc: Location | None = None, name: str | None = None, color: Color | None = None) Iterator[Tuple[Shape, str, Location, Color | None]][source]

Assembly iterator yielding shapes, names, locations and colors.

Parameters:
Return type:

Iterator[Tuple[Shape, str, Location, Color | None]]

__weakref__

list of weak references to the object (if defined)

add(obj: Assembly, loc: Location | None = None, name: str | None = None, color: Color | None = None) Assembly[source]
add(obj: Shape | Workplane | None, loc: Location | None = None, name: str | None = None, color: Color | None = None, metadata: Dict[str, Any] | None = None) Assembly

Add a subassembly to the current assembly.

constrain(q1: str, q2: str, kind: Literal['Plane', 'Point', 'Axis', 'PointInPlane', 'Fixed', 'FixedPoint', 'FixedAxis', 'PointOnLine', 'FixedRotation'], param: Any = None) Assembly[source]
constrain(q1: str, kind: Literal['Plane', 'Point', 'Axis', 'PointInPlane', 'Fixed', 'FixedPoint', 'FixedAxis', 'PointOnLine', 'FixedRotation'], param: Any = None) Assembly
constrain(id1: str, s1: Shape, id2: str, s2: Shape, kind: Literal['Plane', 'Point', 'Axis', 'PointInPlane', 'Fixed', 'FixedPoint', 'FixedAxis', 'PointOnLine', 'FixedRotation'], param: Any = None) Assembly
constrain(id1: str, s1: Shape, kind: Literal['Plane', 'Point', 'Axis', 'PointInPlane', 'Fixed', 'FixedPoint', 'FixedAxis', 'PointOnLine', 'FixedRotation'], param: Any = None) Assembly

Define a new constraint.

export(path: str, exportType: Literal['STEP', 'XML', 'GLTF', 'VTKJS', 'VRML', 'STL'] | None = None, mode: Literal['default', 'fused'] = 'default', tolerance: float = 0.1, angularTolerance: float = 0.1, **kwargs) Assembly[source]

Save assembly to a file.

Parameters:
  • path (str) – Path and filename for writing.

  • exportType (Literal['STEP', 'XML', 'GLTF', 'VTKJS', 'VRML', 'STL'] | None) – export format (default: None, results in format being inferred form the path)

  • mode (Literal['default', 'fused']) – STEP only - See exportAssembly().

  • tolerance (float) – the deflection tolerance, in model units. Only used for glTF, VRML. Default 0.1.

  • angularTolerance (float) – the angular tolerance, in radians. Only used for glTF, VRML. Default 0.1.

  • **kwargs – Additional keyword arguments. Only used for STEP, glTF and STL. See exportAssembly().

  • ascii (bool) – STL only - Sets whether or not STL export should be text or binary

Return type:

Assembly

save(path: str, exportType: Literal['STEP', 'XML', 'GLTF', 'VTKJS', 'VRML', 'STL'] | None = None, mode: Literal['default', 'fused'] = 'default', tolerance: float = 0.1, angularTolerance: float = 0.1, **kwargs) Assembly[source]

Save assembly to a file.

Parameters:
  • path (str) – Path and filename for writing.

  • exportType (Literal['STEP', 'XML', 'GLTF', 'VTKJS', 'VRML', 'STL'] | None) – export format (default: None, results in format being inferred form the path)

  • mode (Literal['default', 'fused']) – STEP only - See exportAssembly().

  • tolerance (float) – the deflection tolerance, in model units. Only used for glTF, VRML. Default 0.1.

  • angularTolerance (float) – the angular tolerance, in radians. Only used for glTF, VRML. Default 0.1.

  • **kwargs – Additional keyword arguments. Only used for STEP, glTF and STL. See exportAssembly().

  • ascii (bool) – STL only - Sets whether or not STL export should be text or binary

Return type:

Assembly

property shapes: List[Shape]

List of Shape objects in the .obj field

solve(verbosity: int = 0) Assembly[source]

Solve the constraints.

Parameters:

verbosity (int)

Return type:

Assembly

toCompound() Compound[source]

Returns a Compound made from this Assembly (including all children) with the current Locations applied. Usually this method would only be used after solving.

Return type:

Compound

traverse() Iterator[Tuple[str, Assembly]][source]

Yield (name, child) pairs in a bottom-up manner

Return type:

Iterator[Tuple[str, Assembly]]

class cadquery.BoundBox(bb: Bnd_Box)[source]

Bases: object

A BoundingBox for an object or set of objects. Wraps the OCP one

Parameters:

bb (Bnd_Box)

__init__(bb: Bnd_Box) None[source]
Parameters:

bb (Bnd_Box)

Return type:

None

__weakref__

list of weak references to the object (if defined)

add(obj: Tuple[float, float, float] | Vector | BoundBox, tol: float | None = None) BoundBox[source]

Returns a modified (expanded) bounding box

obj can be one of several things:
  1. a 3-tuple corresponding to x,y, and z amounts to add

  2. a vector, containing the x,y,z values to add

  3. another bounding box, where a new box will be created that encloses both.

This bounding box is not changed.

Parameters:
  • obj (Tuple[float, float, float] | Vector | BoundBox)

  • tol (float | None)

Return type:

BoundBox

enlarge(tol: float) BoundBox[source]

Returns a modified (expanded) bounding box, expanded in all directions by the tolerance value.

This means that the minimum values of its X, Y and Z intervals of the bounding box are reduced by the absolute value of tol, while the maximum values are increased by the same amount.

Parameters:

tol (float)

Return type:

BoundBox

static findOutsideBox2D(bb1: BoundBox, bb2: BoundBox) BoundBox | None[source]

Compares bounding boxes

Compares bounding boxes. Returns none if neither is inside the other. Returns the outer one if either is outside the other.

BoundBox.isInside works in 3d, but this is a 2d bounding box, so it doesn’t work correctly plus, there was all kinds of rounding error in the built-in implementation i do not understand.

Parameters:
Return type:

BoundBox | None

isInside(b2: BoundBox) bool[source]

Is the provided bounding box inside this one?

Parameters:

b2 (BoundBox)

Return type:

bool

cadquery.CQ

alias of Workplane

class cadquery.Color(name: str)[source]
class cadquery.Color(r: float, g: float, b: float, a: float = 0)
class cadquery.Color

Bases: object

Wrapper for the OCCT color object Quantity_ColorRGBA.

__eq__(other)[source]

Return self==value.

__hash__()[source]

Return hash(self).

__init__(name: str)[source]
__init__(r: float, g: float, b: float, a: float = 0)
__init__()
__weakref__

list of weak references to the object (if defined)

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

Convert Color to RGB tuple.

Return type:

Tuple[float, float, float, float]

class cadquery.Compound(obj: TopoDS_Shape)[source]

Bases: Shape, Mixin3D

a collection of disconnected solids

Parameters:

obj (TopoDS_Shape)

__bool__() bool[source]

Check if empty.

Return type:

bool

ancestors(shape: Shape, kind: Literal['Vertex', 'Edge', 'Wire', 'Face', 'Shell', 'Solid', 'CompSolid', 'Compound']) Compound[source]

Iterate over ancestors, i.e. shapes of same kind within shape that contain elements of self.

Parameters:
  • shape (Shape)

  • kind (Literal['Vertex', 'Edge', 'Wire', 'Face', 'Shell', 'Solid', 'CompSolid', 'Compound'])

Return type:

Compound

cut(*toCut: Shape, tol: float | None = None) Compound[source]

Remove the positional arguments from this Shape.

Parameters:
  • tol (float | None) – Fuzzy mode tolerance

  • toCut (Shape)

Return type:

Compound

fuse(*toFuse: Shape, glue: bool = False, tol: float | None = None) Compound[source]

Fuse shapes together

Parameters:
  • toFuse (Shape)

  • glue (bool)

  • tol (float | None)

Return type:

Compound

intersect(*toIntersect: Shape, tol: float | None = None) Compound[source]

Intersection of the positional arguments and this Shape.

Parameters:
  • tol (float | None) – Fuzzy mode tolerance

  • toIntersect (Shape)

Return type:

Compound

classmethod makeCompound(listOfShapes: Iterable[Shape]) Compound[source]

Create a compound out of a list of shapes

Parameters:

listOfShapes (Iterable[Shape])

Return type:

Compound

classmethod makeText(text: str, size: float, height: float, font: str = 'Arial', fontPath: str | None = None, kind: Literal['regular', 'bold', 'italic'] = 'regular', halign: Literal['center', 'left', 'right'] = 'center', valign: Literal['center', 'top', 'bottom'] = 'center', position: Plane = Plane(origin=(0.0, 0.0, 0.0), xDir=(1.0, 0.0, 0.0), normal=(0.0, 0.0, 1.0))) Shape[source]

Create a 3D text

Parameters:
  • text (str)

  • size (float)

  • height (float)

  • font (str)

  • fontPath (str | None)

  • kind (Literal['regular', 'bold', 'italic'])

  • halign (Literal['center', 'left', 'right'])

  • valign (Literal['center', 'top', 'bottom'])

  • position (Plane)

Return type:

Shape

remove(shape: Shape)[source]

Remove the specified shape.

Parameters:

shape (Shape)

siblings(shape: Shape, kind: Literal['Vertex', 'Edge', 'Wire', 'Face', 'Shell', 'Solid', 'CompSolid', 'Compound'], level: int = 1) Compound[source]

Iterate over siblings, i.e. shapes within shape that share subshapes of kind with the elements of self.

Parameters:
  • shape (Shape)

  • kind (Literal['Vertex', 'Edge', 'Wire', 'Face', 'Shell', 'Solid', 'CompSolid', 'Compound'])

  • level (int)

Return type:

Compound

cadquery.Constraint

alias of ConstraintSpec

class cadquery.DirectionMinMaxSelector(vector: Vector, directionMax: bool = True, tolerance: float = 0.0001)[source]

Bases: CenterNthSelector

Selects objects closest or farthest in the specified direction.

Applicability:

All object types. for a vertex, its point is used. for all other kinds of objects, the center of mass of the object is used.

You can use the string shortcuts >(X|Y|Z) or <(X|Y|Z) if you want to select based on a cardinal direction.

For example this:

CQ(aCube).faces(DirectionMinMaxSelector((0, 0, 1), True))

Means to select the face having the center of mass farthest in the positive z direction, and is the same as:

CQ(aCube).faces(">Z")
Parameters:
  • vector (Vector)

  • directionMax (bool)

  • tolerance (float)

__init__(vector: Vector, directionMax: bool = True, tolerance: float = 0.0001)[source]
Parameters:
  • vector (Vector)

  • directionMax (bool)

  • tolerance (float)

class cadquery.DirectionSelector(vector: Vector, tolerance: float = 0.0001)[source]

Bases: BaseDirSelector

Selects objects aligned with the provided direction.

Applicability:

Linear Edges Planar Faces

Use the string syntax shortcut +/-(X|Y|Z) if you want to select based on a cardinal direction.

Example:

CQ(aCube).faces(DirectionSelector((0, 0, 1)))

selects faces with the normal in the z direction, and is equivalent to:

CQ(aCube).faces("+Z")
Parameters:
  • vector (Vector)

  • tolerance (float)

test(vec: Vector) bool[source]

Test a specified vector. Subclasses override to provide other implementations

Parameters:

vec (Vector)

Return type:

bool

class cadquery.Edge(obj: TopoDS_Shape)[source]

Bases: Shape, Mixin1D

A trimmed curve that represents the border of a face

Parameters:

obj (TopoDS_Shape)

arcCenter() Vector[source]

Center of an underlying circle or ellipse geometry.

Return type:

Vector

close() Edge | Wire[source]

Close an Edge

Return type:

Edge | Wire

classmethod makeBezier(points: List[Vector]) Edge[source]

Create a cubic Bézier Curve from the points.

Parameters:

points (List[Vector]) – a list of Vectors that represent the points. The edge will pass through the first and the last point, and the inner points are Bézier control points.

Returns:

An edge

Return type:

Edge

classmethod makeEllipse(x_radius: float, y_radius: float, pnt: ~cadquery.occ_impl.geom.Vector | ~typing.Tuple[int | float, int | float] | ~typing.Tuple[int | float, int | float, int | float] = Vector: (0.0, 0.0, 0.0), dir: ~cadquery.occ_impl.geom.Vector | ~typing.Tuple[int | float, int | float] | ~typing.Tuple[int | float, int | float, int | float] = Vector: (0.0, 0.0, 1.0), xdir: ~cadquery.occ_impl.geom.Vector | ~typing.Tuple[int | float, int | float] | ~typing.Tuple[int | float, int | float, int | float] = Vector: (1.0, 0.0, 0.0), angle1: float = 360.0, angle2: float = 360.0, sense: ~typing.Literal[-1, 1] = 1) Edge[source]

Makes an Ellipse centered at the provided point, having normal in the provided direction.

Parameters:
  • cls

  • x_radius (float) – x radius of the ellipse (along the x-axis of plane the ellipse should lie in)

  • y_radius (float) – y radius of the ellipse (along the y-axis of plane the ellipse should lie in)

  • pnt (Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float]) – vector representing the center of the ellipse

  • dir (Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float]) – vector representing the direction of the plane the ellipse should lie in

  • angle1 (float) – start angle of arc

  • angle2 (float) – end angle of arc (angle2 == angle1 return closed ellipse = default)

  • sense (Literal[-1, 1]) – clockwise (-1) or counter clockwise (1)

  • xdir (Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float])

Returns:

an Edge

Return type:

Edge

classmethod makeLine(v1: Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float], v2: Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float]) Edge[source]

Create a line between two points

Parameters:
  • v1 (Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float]) – Vector that represents the first point

  • v2 (Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float]) – Vector that represents the second point

Returns:

A linear edge between the two provided points

Return type:

Edge

classmethod makeSpline(listOfVector: List[Vector], tangents: Sequence[Vector] | None = None, periodic: bool = False, parameters: Sequence[float] | None = None, scale: bool = True, tol: float = 1e-06) Edge[source]

Interpolate a spline through the provided points.

Parameters:
  • listOfVector (List[Vector]) – a list of Vectors that represent the points

  • tangents (Sequence[Vector] | None) – tuple of Vectors specifying start and finish tangent

  • periodic (bool) – creation of periodic curves

  • parameters (Sequence[float] | None) – the value of the parameter at each interpolation point. (The interpolated curve is represented as a vector-valued function of a scalar parameter.) If periodic == True, then len(parameters) must be len(intepolation points) + 1, otherwise len(parameters) must be equal to len(interpolation points).

  • scale (bool) – whether to scale the specified tangent vectors before interpolating. Each tangent is scaled, so it’s length is equal to the derivative of the Lagrange interpolated curve. I.e., set this to True, if you want to use only the direction of the tangent vectors specified by tangents, but not their magnitude.

  • tol (float) – tolerance of the algorithm (consult OCC documentation). Used to check that the specified points are not too close to each other, and that tangent vectors are not too short. (In either case interpolation may fail.)

Returns:

an Edge

Return type:

Edge

classmethod makeSplineApprox(listOfVector: List[Vector], tol: float = 0.001, smoothing: Tuple[float, float, float] | None = None, minDeg: int = 1, maxDeg: int = 6) Edge[source]

Approximate a spline through the provided points.

Parameters:
  • listOfVector (List[Vector]) – a list of Vectors that represent the points

  • tol (float) – tolerance of the algorithm (consult OCC documentation).

  • smoothing (Tuple[float, float, float] | None) – optional tuple of 3 weights use for variational smoothing (default: None)

  • minDeg (int) – minimum spline degree. Enforced only when smothing is None (default: 1)

  • maxDeg (int) – maximum spline degree (default: 6)

Returns:

an Edge

Return type:

Edge

classmethod makeTangentArc(v1: Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float], v2: Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float], v3: Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float]) Edge[source]

Makes a tangent arc from point v1, in the direction of v2 and ends at v3.

Parameters:
  • cls

  • v1 (Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float]) – start vector

  • v2 (Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float]) – tangent vector

  • v3 (Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float]) – end vector

Returns:

an edge

Return type:

Edge

classmethod makeThreePointArc(v1: Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float], v2: Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float], v3: Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float]) Edge[source]

Makes a three point arc through the provided points

Parameters:
  • cls

  • v1 (Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float]) – start vector

  • v2 (Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float]) – middle vector

  • v3 (Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float]) – end vector

Returns:

an edge object through the three points

Return type:

Edge

trim(u0: float | int, u1: float | int) Edge[source]

Trim the edge in the parametric space to (u0, u1).

NB: this operation is done on the base geometry.

Parameters:
  • u0 (float | int)

  • u1 (float | int)

Return type:

Edge

class cadquery.Face(obj: TopoDS_Shape)[source]

Bases: Shape

a bounded surface that represents part of the boundary of a solid

Parameters:

obj (TopoDS_Shape)

Center() Vector[source]
Returns:

The point of the center of mass of this Shape

Return type:

Vector

chamfer2D(d: float, vertices: Iterable[Vertex]) Face[source]

Apply 2D chamfer to a face

Parameters:
  • d (float)

  • vertices (Iterable[Vertex])

Return type:

Face

fillet2D(radius: float, vertices: Iterable[Vertex]) Face[source]

Apply 2D fillet to a face

Parameters:
  • radius (float)

  • vertices (Iterable[Vertex])

Return type:

Face

isoline(param: float | int, direction: Literal['u', 'v'] = 'v') Edge[source]

Construct an isoline.

Parameters:
  • param (float | int)

  • direction (Literal['u', 'v'])

Return type:

Edge

isolines(params: Iterable[float | int], direction: Literal['u', 'v'] = 'v') List[Edge][source]

Construct multiple isolines.

Parameters:
  • params (Iterable[float | int])

  • direction (Literal['u', 'v'])

Return type:

List[Edge]

classmethod makeFromWires(outerWire: Wire, innerWires: List[Wire] = []) Face[source]

Makes a planar face from one or more wires

Parameters:
  • outerWire (Wire)

  • innerWires (List[Wire])

Return type:

Face

classmethod makeNSidedSurface(edges: ~typing.Iterable[~cadquery.occ_impl.shapes.Edge | ~cadquery.occ_impl.shapes.Wire], constraints: ~typing.Iterable[~cadquery.occ_impl.shapes.Edge | ~cadquery.occ_impl.shapes.Wire | ~cadquery.occ_impl.geom.Vector | ~typing.Tuple[int | float, int | float] | ~typing.Tuple[int | float, int | float, int | float] | ~OCP.gp.gp_Pnt], continuity: ~OCP.GeomAbs.GeomAbs_Shape = <GeomAbs_Shape.GeomAbs_C0: 0>, degree: int = 3, nbPtsOnCur: int = 15, nbIter: int = 2, anisotropy: bool = False, tol2d: float = 1e-05, tol3d: float = 0.0001, tolAng: float = 0.01, tolCurv: float = 0.1, maxDeg: int = 8, maxSegments: int = 9) Face[source]

Returns a surface enclosed by a closed polygon defined by ‘edges’ and ‘constraints’.

Parameters:
  • edges (list of edges or wires) – edges

  • constraints (list of points or edges) – constraints

  • continuity (GeomAbs_Shape) – OCC.Core.GeomAbs continuity condition

  • degree (int) – >=2

  • nbPtsOnCur (int) – number of points on curve >= 15

  • nbIter (int) – number of iterations >= 2

  • anisotropy (bool) – bool Anisotropy

  • tol2d (float) – 2D tolerance >0

  • tol3d (float) – 3D tolerance >0

  • tolAng (float) – angular tolerance

  • tolCurv (float) – tolerance for curvature >0

  • maxDeg (int) – highest polynomial degree >= 2

  • maxSegments (int) – greatest number of segments >= 2

Return type:

Face

classmethod makeRuledSurface(edgeOrWire1: Edge, edgeOrWire2: Edge) Face[source]
classmethod makeRuledSurface(edgeOrWire1: Wire, edgeOrWire2: Wire) Face

makeRuledSurface(Edge|Wire,Edge|Wire) – Make a ruled surface Create a ruled surface out of two edges or wires. If wires are used then these must have the same number of edges

classmethod makeSplineApprox(points: List[List[Vector]], tol: float = 0.01, smoothing: Tuple[float, float, float] | None = None, minDeg: int = 1, maxDeg: int = 3) Face[source]

Approximate a spline surface through the provided points.

Parameters:
  • points (List[List[Vector]]) – a 2D list of Vectors that represent the points

  • tol (float) – tolerance of the algorithm (consult OCC documentation).

  • smoothing (Tuple[float, float, float] | None) – optional tuple of 3 weights use for variational smoothing (default: None)

  • minDeg (int) – minimum spline degree. Enforced only when smothing is None (default: 1)

  • maxDeg (int) – maximum spline degree (default: 6)

Return type:

Face

normalAt(u: float | int, v: float | int) Tuple[Vector, Vector][source]
normalAt(locationVector: Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float] | None = None) Vector

Computes the normal vector at the desired location on the face.

Returns:

a vector representing the direction

Parameters:

locationVector (a vector that lies on the surface.) – the location to compute the normal at. If none, the center of the face is used.

Return type:

Vector

Computes the normal vector at the desired location in the u,v parameter space.

Returns:

a vector representing the normal direction and the position

Parameters:
  • u – the u parametric location to compute the normal at.

  • v – the v parametric location to compute the normal at.

  • locationVector (Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float] | None)

Return type:

Vector

normals(us: Iterable[float | int], vs: Iterable[float | int]) Tuple[List[Vector], List[Vector]][source]

Computes the normal vectors at the desired locations in the u,v parameter space.

Returns:

a tuple of list of vectors representing the normal directions and the positions

Parameters:
  • us (Iterable[float | int]) – the u parametric locations to compute the normal at.

  • vs (Iterable[float | int]) – the v parametric locations to compute the normal at.

Return type:

Tuple[List[Vector], List[Vector]]

thicken(thickness: float) Solid[source]

Return a thickened face

Parameters:

thickness (float)

Return type:

Solid

toArcs(tolerance: float = 0.001) Face[source]

Approximate planar face with arcs and straight line segments.

Parameters:

tolerance (float) – Approximation tolerance.

Return type:

Face

toPln() gp_Pln[source]

Convert this face to a gp_Pln.

Note the Location of the resulting plane may not equal the center of this face, however the resulting plane will still contain the center of this face.

Return type:

gp_Pln

trim(u0: float | int, u1: float | int, v0: float | int, v1: float | int, tol: float | int = 1e-06) Face[source]

Trim the face in the parametric space to (u0, u1).

NB: this operation is done on the base geometry.

Parameters:
  • u0 (float | int)

  • u1 (float | int)

  • v0 (float | int)

  • v1 (float | int)

  • tol (float | int)

Return type:

Face

class cadquery.Location(t: Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float])[source]

Bases: object

Location in 3D space. Depending on usage can be absolute or relative.

This class wraps the TopLoc_Location class from OCCT. It can be used to move Shape objects in both relative and absolute manner. It is the preferred type to locate objects in CQ.

Parameters:

t (Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float])

__init__(T: gp_Trsf) None[source]
__init__(t: Plane, v: Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float]) None
__init__(t: Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float]) None
__init__(T: TopLoc_Location) None
__init__(t: Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float], ax: Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float], angle: int | float) None
__init__(t: Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float], angles: Tuple[int | float, int | float, int | float]) None
__init__(t: Plane) None
__init__(x: int | float = 0, y: int | float = 0, z: int | float = 0, rx: int | float = 0, ry: int | float = 0, rz: int | float = 0) None

Location with translation t with respect to the original location.

Location with translation (x,y,z) and 3 rotation angles.

Location corresponding to the location of the Plane t.

Location corresponding to the angular location of the Plane t with translation v.

Location wrapping the low-level TopLoc_Location object t

Location wrapping the low-level gp_Trsf object t

Location with translation t and rotation around ax by angle

with respect to the original location.

Location with translation t and 3 rotation angles.

Parameters:

t (Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float])

Return type:

None

__weakref__

list of weak references to the object (if defined)

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

Convert the location to a translation, rotation tuple.

Return type:

Tuple[Tuple[float, float, float], Tuple[float, float, float]]

class cadquery.Matrix[source]
class cadquery.Matrix(matrix: gp_GTrsf | gp_Trsf)
class cadquery.Matrix(matrix: Sequence[Sequence[float]])

Bases: object

A 3d , 4x4 transformation matrix.

Used to move geometry in space.

The provided “matrix” parameter may be None, a gp_GTrsf, or a nested list of values.

If given a nested list, it is expected to be of the form:

[[m11, m12, m13, m14],

[m21, m22, m23, m24], [m31, m32, m33, m34]]

A fourth row may be given, but it is expected to be: [0.0, 0.0, 0.0, 1.0] since this is a transform matrix.

__getitem__(rc: Tuple[int, int]) float[source]

Provide Matrix[r, c] syntax for accessing individual values. The row and column parameters start at zero, which is consistent with most python libraries, but is counter to gp_GTrsf(), which is 1-indexed.

Parameters:

rc (Tuple[int, int])

Return type:

float

__init__() None[source]
__init__(matrix: gp_GTrsf | gp_Trsf) None
__init__(matrix: Sequence[Sequence[float]]) None
__repr__() str[source]

Generate a valid python expression representing this Matrix

Return type:

str

__weakref__

list of weak references to the object (if defined)

transposed_list() Sequence[float][source]

Needed by the cqparts gltf exporter

Return type:

Sequence[float]

class cadquery.NearestToPointSelector(pnt)[source]

Bases: Selector

Selects object nearest the provided point.

If the object is a vertex or point, the distance is used. For other kinds of shapes, the center of mass is used to to compute which is closest.

Applicability: All Types of Shapes

Example:

CQ(aCube).vertices(NearestToPointSelector((0, 1, 0)))

returns the vertex of the unit cube closest to the point x=0,y=1,z=0

__init__(pnt)[source]
filter(objectList: Sequence[Shape])[source]

Filter the provided list.

The default implementation returns the original list unfiltered.

Parameters:

objectList (list of OCCT primitives) – list to filter

Returns:

filtered list

class cadquery.ParallelDirSelector(vector: Vector, tolerance: float = 0.0001)[source]

Bases: BaseDirSelector

Selects objects parallel with the provided direction.

Applicability:

Linear Edges Planar Faces

Use the string syntax shortcut |(X|Y|Z) if you want to select based on a cardinal direction.

Example:

CQ(aCube).faces(ParallelDirSelector((0, 0, 1)))

selects faces with the normal parallel to the z direction, and is equivalent to:

CQ(aCube).faces("|Z")
Parameters:
  • vector (Vector)

  • tolerance (float)

test(vec: Vector) bool[source]

Test a specified vector. Subclasses override to provide other implementations

Parameters:

vec (Vector)

Return type:

bool

class cadquery.PerpendicularDirSelector(vector: Vector, tolerance: float = 0.0001)[source]

Bases: BaseDirSelector

Selects objects perpendicular with the provided direction.

Applicability:

Linear Edges Planar Faces

Use the string syntax shortcut #(X|Y|Z) if you want to select based on a cardinal direction.

Example:

CQ(aCube).faces(PerpendicularDirSelector((0, 0, 1)))

selects faces with the normal perpendicular to the z direction, and is equivalent to:

CQ(aCube).faces("#Z")
Parameters:
  • vector (Vector)

  • tolerance (float)

test(vec: Vector) bool[source]

Test a specified vector. Subclasses override to provide other implementations

Parameters:

vec (Vector)

Return type:

bool

class cadquery.Plane(origin: Tuple[float, float, float] | Vector, xDir: Tuple[float, float, float] | Vector | None = None, normal: Tuple[float, float, float] | Vector = (0, 0, 1))[source]

Bases: object

A 2D coordinate system in space

A 2D coordinate system in space, with the x-y axes on the plane, and a particular point as the origin.

A plane allows the use of 2D coordinates, which are later converted to global, 3d coordinates when the operations are complete.

Frequently, it is not necessary to create work planes, as they can be created automatically from faces.

Parameters:
  • origin (Tuple[float, float, float] | Vector)

  • xDir (Vector)

  • normal (Tuple[float, float, float] | Vector)

__eq__(other)[source]

Return self==value.

__hash__ = None
__init__(origin: Tuple[float, float, float] | Vector, xDir: Tuple[float, float, float] | Vector | None = None, normal: Tuple[float, float, float] | Vector = (0, 0, 1))[source]

Create a Plane with an arbitrary orientation

Parameters:
  • origin (Tuple[float, float, float] | Vector) – the origin in global coordinates

  • xDir (Tuple[float, float, float] | Vector | None) – an optional vector representing the xDirection.

  • normal (Tuple[float, float, float] | Vector) – the normal direction for the plane

Raises:

ValueError – if the specified xDir is not orthogonal to the provided normal

__ne__(other)[source]

Return self!=value.

__repr__()[source]

Return repr(self).

__weakref__

list of weak references to the object (if defined)

classmethod named(stdName: str, origin=(0, 0, 0)) Plane[source]

Create a predefined Plane based on the conventional names.

Parameters:
  • stdName (string) – one of (XY|YZ|ZX|XZ|YX|ZY|front|back|left|right|top|bottom)

  • origin (3-tuple of the origin of the new plane, in global coordinates.) – the desired origin, specified in global coordinates

Return type:

Plane

Available named planes are as follows. Direction references refer to the global directions.

Name

xDir

yDir

zDir

XY

+x

+y

+z

YZ

+y

+z

+x

ZX

+z

+x

+y

XZ

+x

+z

-y

YX

+y

+x

-z

ZY

+z

+y

-x

front

+x

+y

+z

back

-x

+y

-z

left

+z

+y

-x

right

-z

+y

+x

top

+x

-z

+y

bottom

+x

+z

-y

rotated(rotate=(0, 0, 0))[source]

Returns a copy of this plane, rotated about the specified axes

Since the z axis is always normal the plane, rotating around Z will always produce a plane that is parallel to this one.

The origin of the workplane is unaffected by the rotation.

Rotations are done in order x, y, z. If you need a different order, manually chain together multiple rotate() commands.

Parameters:

rotate – Vector [xDegrees, yDegrees, zDegrees]

Returns:

a copy of this plane rotated as requested.

setOrigin2d(x, y)[source]

Set a new origin in the plane itself

Set a new origin in the plane itself. The plane’s orientation and xDrection are unaffected.

Parameters:
  • x (float) – offset in the x direction

  • y (float) – offset in the y direction

Returns:

void

The new coordinates are specified in terms of the current 2D system. As an example:

p = Plane.XY() p.setOrigin2d(2, 2) p.setOrigin2d(2, 2)

results in a plane with its origin at (x, y) = (4, 4) in global coordinates. Both operations were relative to local coordinates of the plane.

toLocalCoords(obj)[source]

Project the provided coordinates onto this plane

Parameters:

obj – an object or vector to convert

Returns:

an object of the same type, but converted to local coordinates

Most of the time, the z-coordinate returned will be zero, because most operations based on a plane are all 2D. Occasionally, though, 3D points outside of the current plane are transformed. One such example is Workplane.box(), where 3D corners of a box are transformed to orient the box in space correctly.

toWorldCoords(tuplePoint) Vector[source]

Convert a point in local coordinates to global coordinates

Parameters:

tuplePoint (a 2 or three tuple of float. The third value is taken to be zero if not supplied.) – point in local coordinates to convert.

Returns:

a Vector in global coordinates

Return type:

Vector

class cadquery.Selector[source]

Bases: object

Filters a list of objects.

Filters must provide a single method that filters objects.

__weakref__

list of weak references to the object (if defined)

filter(objectList: Sequence[Shape]) List[Shape][source]

Filter the provided list.

The default implementation returns the original list unfiltered.

Parameters:

objectList (list of OCCT primitives) – list to filter

Returns:

filtered list

Return type:

List[Shape]

class cadquery.Shape(obj: TopoDS_Shape)[source]

Bases: object

Represents a shape in the system. Wraps TopoDS_Shape.

Parameters:

obj (TopoDS_Shape)

Area() float[source]
Returns:

The surface area of all faces in this Shape

Return type:

float

BoundingBox(tolerance: float | None = None) BoundBox[source]

Create a bounding box for this Shape.

Parameters:

tolerance (float | None) – Tolerance value passed to BoundBox

Returns:

A BoundBox object for this Shape

Return type:

BoundBox

Center() Vector[source]
Returns:

The point of the center of mass of this Shape

Return type:

Vector

CenterOfBoundBox(tolerance: float | None = None) Vector[source]
Parameters:

tolerance (float | None) – Tolerance passed to the BoundingBox() method

Returns:

Center of the bounding box of this shape

Return type:

Vector

Closed() bool[source]
Returns:

The closedness flag

Return type:

bool

static CombinedCenter(objects: Iterable[Shape]) Vector[source]

Calculates the center of mass of multiple objects.

Parameters:

objects (Iterable[Shape]) – A list of objects with mass

Return type:

Vector

static CombinedCenterOfBoundBox(objects: List[Shape]) Vector[source]

Calculates the center of a bounding box of multiple objects.

Parameters:

objects (List[Shape]) – A list of objects

Return type:

Vector

CompSolids() List[CompSolid][source]
Returns:

All the compsolids in this Shape

Return type:

List[CompSolid]

Compounds() List[Compound][source]
Returns:

All the compounds in this Shape

Return type:

List[Compound]

Edges() List[Edge][source]
Returns:

All the edges in this Shape

Return type:

List[Edge]

Faces() List[Face][source]
Returns:

All the faces in this Shape

Return type:

List[Face]

Shells() List[Shell][source]
Returns:

All the shells in this Shape

Return type:

List[Shell]

Solids() List[Solid][source]
Returns:

All the solids in this Shape

Return type:

List[Solid]

Vertices() List[Vertex][source]
Returns:

All the vertices in this Shape

Return type:

List[Vertex]

Volume() float[source]
Returns:

The volume of this Shape

Return type:

float

Wires() List[Wire][source]
Returns:

All the wires in this Shape

Return type:

List[Wire]

__add__(other: Shape) Shape[source]

Fuse self and other.

Parameters:

other (Shape)

Return type:

Shape

__eq__(other) bool[source]

Return self==value.

Return type:

bool

__hash__() int[source]

Return hash(self).

Return type:

int

__init__(obj: TopoDS_Shape)[source]
Parameters:

obj (TopoDS_Shape)

__iter__() Iterator[Shape][source]

Iterate over subshapes.

Return type:

Iterator[Shape]

__mul__(other: Shape) Shape[source]

Intersect self and other.

Parameters:

other (Shape)

Return type:

Shape

__sub__(other: Shape) Shape[source]

Subtract other from self.

Parameters:

other (Shape)

Return type:

Shape

__truediv__(other: Shape) Shape[source]

Split self with other.

Parameters:

other (Shape)

Return type:

Shape

__weakref__

list of weak references to the object (if defined)

ancestors(shape: Shape, kind: Literal['Vertex', 'Edge', 'Wire', 'Face', 'Shell', 'Solid', 'CompSolid', 'Compound']) Compound[source]

Iterate over ancestors, i.e. shapes of same kind within shape that contain self.

Parameters:
  • shape (Shape)

  • kind (Literal['Vertex', 'Edge', 'Wire', 'Face', 'Shell', 'Solid', 'CompSolid', 'Compound'])

Return type:

Compound

classmethod cast(obj: TopoDS_Shape, forConstruction: bool = False) Shape[source]

Returns the right type of wrapper, given a OCCT object

Parameters:
  • obj (TopoDS_Shape)

  • forConstruction (bool)

Return type:

Shape

static centerOfMass(obj: Shape) Vector[source]

Calculates the center of ‘mass’ of an object.

Parameters:

obj (Shape) – Compute the center of mass of this object

Return type:

Vector

clean() T[source]

Experimental clean using ShapeUpgrade

Parameters:

self (T)

Return type:

T

static computeMass(obj: Shape) float[source]

Calculates the ‘mass’ of an object.

Parameters:

obj (Shape) – Compute the mass of this object

Return type:

float

copy(mesh: bool = False) T[source]

Creates a new object that is a copy of this object.

Parameters:
  • self (T)

  • mesh (bool) – should I copy the triangulation too (default: False)

Returns:

a copy of the object

Return type:

T

cut(*toCut: Shape, tol: float | None = None) Shape[source]

Remove the positional arguments from this Shape.

Parameters:
  • tol (float | None) – Fuzzy mode tolerance

  • toCut (Shape)

Return type:

Shape

distance(other: Shape) float[source]

Minimal distance between two shapes

Parameters:

other (Shape)

Return type:

float

distances(*others: Shape) Iterator[float][source]

Minimal distances to between self and other shapes

Parameters:

others (Shape)

Return type:

Iterator[float]

edges(selector: Selector | str | None = None) Shape[source]

Select edges.

Parameters:

selector (Selector | str | None)

Return type:

Shape

export(fname: str, tolerance: float = 0.1, angularTolerance: float = 0.1, opt: Dict[str, Any] | None = None)[source]

Export Shape to file.

Parameters:
  • self (T)

  • fname (str)

  • tolerance (float)

  • angularTolerance (float)

  • opt (Dict[str, Any] | None)

exportBin(f: str | BytesIO) bool[source]

Export this shape to a binary BREP file.

Parameters:

f (str | BytesIO)

Return type:

bool

exportBrep(f: str | BytesIO) bool[source]

Export this shape to a BREP file

Parameters:

f (str | BytesIO)

Return type:

bool

exportStep(fileName: str, **kwargs) IFSelect_ReturnStatus[source]

Export this shape to a STEP file.

kwargs is used to provide optional keyword arguments to configure the exporter.

Parameters:
  • fileName (str) – Path and filename for writing.

  • write_pcurves (bool) –

    Enable or disable writing parametric curves to the STEP file. Default True.

    If False, writes STEP file without pcurves. This decreases the size of the resulting STEP file.

  • precision_mode (int) – Controls the uncertainty value for STEP entities. Specify -1, 0, or 1. Default 0. See OCCT documentation.

Return type:

IFSelect_ReturnStatus

exportStl(fileName: str, tolerance: float = 0.001, angularTolerance: float = 0.1, ascii: bool = False, relative: bool = True, parallel: bool = True) bool[source]

Exports a shape to a specified STL file.

Parameters:
  • fileName (str) – The path and file name to write the STL output to.

  • tolerance (float) – A linear deflection setting which limits the distance between a curve and its tessellation. Setting this value too low will result in large meshes that can consume computing resources. Setting the value too high can result in meshes with a level of detail that is too low. Default is 1e-3, which is a good starting point for a range of cases.

  • angularTolerance (float) – Angular deflection setting which limits the angle between subsequent segments in a polyline. Default is 0.1.

  • ascii (bool) – Export the file as ASCII (True) or binary (False) STL format. Default is binary.

  • relative (bool) – If True, tolerance will be scaled by the size of the edge being meshed. Default is True. Setting this value to True may cause large features to become faceted, or small features dense.

  • parallel (bool) – If True, OCCT will use parallel processing to mesh the shape. Default is True.

Return type:

bool

faces(selector: Selector | str | None = None) Shape[source]

Select faces.

Parameters:

selector (Selector | str | None)

Return type:

Shape

facesIntersectedByLine(point: Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float], axis: Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float], tol: float = 0.0001, direction: Literal['AlongAxis', 'Opposite'] | None = None)[source]

Computes the intersections between the provided line and the faces of this Shape

Parameters:
  • point (Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float]) – Base point for defining a line

  • axis (Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float]) – Axis on which the line rests

  • tol (float) – Intersection tolerance

  • direction (Literal['AlongAxis', 'Opposite'] | None) – Valid values: “AlongAxis”, “Opposite”; If specified, will ignore all faces that are not in the specified direction including the face where the point lies if it is the case

Returns:

A list of intersected faces sorted by distance from point

fix() T[source]

Try to fix shape if not valid

Parameters:

self (T)

Return type:

T

fuse(*toFuse: Shape, glue: bool = False, tol: float | None = None) Shape[source]

Fuse the positional arguments with this Shape.

Parameters:
  • glue (bool) – Sets the glue option for the algorithm, which allows increasing performance of the intersection of the input shapes

  • tol (float | None) – Fuzzy mode tolerance

  • toFuse (Shape)

Return type:

Shape

geomType() Literal['Vertex', 'Wire', 'Shell', 'Solid', 'Compound', 'PLANE', 'CYLINDER', 'CONE', 'SPHERE', 'TORUS', 'BEZIER', 'BSPLINE', 'REVOLUTION', 'EXTRUSION', 'OFFSET', 'OTHER', 'LINE', 'CIRCLE', 'ELLIPSE', 'HYPERBOLA', 'PARABOLA'][source]

Gets the underlying geometry type.

Implementations can return any values desired, but the values the user uses in type filters should correspond to these.

As an example, if a user does:

CQ(object).faces("%mytype")

The expectation is that the geomType attribute will return ‘mytype’

The return values depend on the type of the shape:

Vertex: always ‘Vertex’
Edge: LINE, CIRCLE, ELLIPSE, HYPERBOLA, PARABOLA, BEZIER,
BSPLINE, OFFSET, OTHER
Face: PLANE, CYLINDER, CONE, SPHERE, TORUS, BEZIER, BSPLINE,
REVOLUTION, EXTRUSION, OFFSET, OTHER
Solid: ‘Solid’
Shell: ‘Shell’
Compound: ‘Compound’
Wire: ‘Wire’
Returns:

A string according to the geometry type

Return type:

Literal[‘Vertex’, ‘Wire’, ‘Shell’, ‘Solid’, ‘Compound’, ‘PLANE’, ‘CYLINDER’, ‘CONE’, ‘SPHERE’, ‘TORUS’, ‘BEZIER’, ‘BSPLINE’, ‘REVOLUTION’, ‘EXTRUSION’, ‘OFFSET’, ‘OTHER’, ‘LINE’, ‘CIRCLE’, ‘ELLIPSE’, ‘HYPERBOLA’, ‘PARABOLA’]

hashCode() int[source]

Returns a hashed value denoting this shape. It is computed from the TShape and the Location. The Orientation is not used.

Return type:

int

classmethod importBin(f: str | BytesIO) Shape[source]

Import shape from a binary BREP file.

Parameters:

f (str | BytesIO)

Return type:

Shape

classmethod importBrep(f: str | BytesIO) Shape[source]

Import shape from a BREP file

Parameters:

f (str | BytesIO)

Return type:

Shape

intersect(*toIntersect: Shape, tol: float | None = None) Shape[source]

Intersection of the positional arguments and this Shape.

Parameters:
  • tol (float | None) – Fuzzy mode tolerance

  • toIntersect (Shape)

Return type:

Shape

isEqual(other: Shape) bool[source]

Returns True if two shapes are equal, i.e. if they share the same TShape with the same Locations and Orientations. Also see isSame().

Parameters:

other (Shape)

Return type:

bool

isNull() bool[source]

Returns true if this shape is null. In other words, it references no underlying shape with the potential to be given a location and an orientation.

Return type:

bool

isSame(other: Shape) bool[source]

Returns True if other and this shape are same, i.e. if they share the same TShape with the same Locations. Orientations may differ. Also see isEqual()

Parameters:

other (Shape)

Return type:

bool

isValid() bool[source]

Returns True if no defect is detected on the shape S or any of its subshapes. See the OCCT docs on BRepCheck_Analyzer::IsValid for a full description of what is checked.

Return type:

bool

locate(loc: Location) T[source]

Apply a location in absolute sense to self.

Parameters:
Return type:

T

located(loc: Location) T[source]

Apply a location in absolute sense to a copy of self.

Parameters:
Return type:

T

location() Location[source]

Return the current location

Return type:

Location

static matrixOfInertia(obj: Shape) List[List[float]][source]

Calculates the matrix of inertia of an object. Since the part’s density is unknown, this result is inertia/density with units of [1/length]. :param obj: Compute the matrix of inertia of this object

Parameters:

obj (Shape)

Return type:

List[List[float]]

mesh(tolerance: float, angularTolerance: float = 0.1)[source]

Generate triangulation if none exists.

Parameters:
  • tolerance (float)

  • angularTolerance (float)

mirror(mirrorPlane: Literal['XY', 'YX', 'XZ', 'ZX', 'YZ', 'ZY'] | Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float] = 'XY', basePointVector: Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float] = (0, 0, 0)) Shape[source]

Applies a mirror transform to this Shape. Does not duplicate objects about the plane.

Parameters:
  • mirrorPlane (Literal['XY', 'YX', 'XZ', 'ZX', 'YZ', 'ZY'] | ~cadquery.occ_impl.geom.Vector | ~typing.Tuple[int | float, int | float] | ~typing.Tuple[int | float, int | float, int | float]) – The direction of the plane to mirror about - one of ‘XY’, ‘XZ’ or ‘YZ’

  • basePointVector (Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float]) – The origin of the plane to mirror about

Returns:

The mirrored shape

Return type:

Shape

move(x: float | int = 0, y: float | int = 0, z: float | int = 0, rx: float | int = 0, ry: float | int = 0, rz: float | int = 0) T[source]
move(loc: Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float]) T
move(loc: Location) T

Apply a location in relative sense (i.e. update current location) to self.

Apply translation and rotation in relative sense (i.e. update current location) to self.

Apply a VectorLike in relative sense (i.e. update current location) to self.

Parameters:
Return type:

T

moved(loc1: Location, loc2: Location, *locs: Location) T[source]
moved(locs: Sequence[Location]) T
moved(loc: Location) T
moved(loc1: Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float], loc2: Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float], *locs: Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float]) T
moved(x: float | int = 0, y: float | int = 0, z: float | int = 0, rx: float | int = 0, ry: float | int = 0, rz: float | int = 0) T
moved(loc: Sequence[Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float]]) T
moved(loc: Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float]) T

Apply a location in relative sense (i.e. update current location) to a copy of self.

Apply multiple locations.

Apply multiple locations.

Apply translation and rotation in relative sense to a copy of self.

Apply a VectorLike in relative sense to a copy of self.

Apply multiple VectorLikes in relative sense to a copy of self.

Apply multiple VectorLikes in relative sense to a copy of self.

Parameters:
Return type:

T

rotate(startVector: Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float], endVector: Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float], angleDegrees: float) T[source]

Rotates a shape around an axis.

Parameters:
  • self (T)

  • startVector (either a 3-tuple or a Vector) – start point of rotation axis

  • endVector (either a 3-tuple or a Vector) – end point of rotation axis

  • angleDegrees (float) – angle to rotate, in degrees

Returns:

a copy of the shape, rotated

Return type:

T

scale(factor: float) Shape[source]

Scales this shape through a transformation.

Parameters:

factor (float)

Return type:

Shape

shells(selector: Selector | str | None = None) Shape[source]

Select shells.

Parameters:

selector (Selector | str | None)

Return type:

Shape

siblings(shape: Shape, kind: Literal['Vertex', 'Edge', 'Wire', 'Face', 'Shell', 'Solid', 'CompSolid', 'Compound'], level: int = 1) Compound[source]

Iterate over siblings, i.e. shapes within shape that share subshapes of kind with self.

Parameters:
  • shape (Shape)

  • kind (Literal['Vertex', 'Edge', 'Wire', 'Face', 'Shell', 'Solid', 'CompSolid', 'Compound'])

  • level (int)

Return type:

Compound

solids(selector: Selector | str | None = None) Shape[source]

Select solids.

Parameters:

selector (Selector | str | None)

Return type:

Shape

split(*splitters: Shape) Shape[source]

Split this shape with the positional arguments.

Parameters:

splitters (Shape)

Return type:

Shape

toSplines(degree: int = 3, tolerance: float = 0.001, nurbs: bool = False) T[source]

Approximate shape with b-splines of the specified degree.

Parameters:
  • self (T)

  • degree (int) – Maximum degree.

  • tolerance (float) – Approximation tolerance.

  • nurbs (bool) – Use rational splines.

Return type:

T

toVtkPolyData(tolerance: float | None = None, angularTolerance: float | None = None, normals: bool = False) vtkPolyData[source]

Convert shape to vtkPolyData

Parameters:
  • tolerance (float | None)

  • angularTolerance (float | None)

  • normals (bool)

Return type:

vtkPolyData

transformGeometry(tMatrix: Matrix) Shape[source]

Transforms this shape by tMatrix.

WARNING: transformGeometry will sometimes convert lines and circles to splines, but it also has the ability to handle skew and stretching transformations.

If your transformation is only translation and rotation, it is safer to use transformShape(), which doesn’t change the underlying type of the geometry, but cannot handle skew transformations.

Parameters:

tMatrix (Matrix) – The transformation matrix

Returns:

a copy of the object, but with geometry transformed instead of just rotated.

Return type:

Shape

transformShape(tMatrix: Matrix) Shape[source]

Transforms this Shape by tMatrix. Also see transformGeometry().

Parameters:

tMatrix (Matrix) – The transformation matrix

Returns:

a copy of the object, transformed by the provided matrix, with all objects keeping their type

Return type:

Shape

translate(vector: Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float]) T[source]

Translates this shape through a transformation.

Parameters:
  • self (T)

  • vector (Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float])

Return type:

T

vertices(selector: Selector | str | None = None) Shape[source]

Select vertices.

Parameters:

selector (Selector | str | None)

Return type:

Shape

wires(selector: Selector | str | None = None) Shape[source]

Select wires.

Parameters:

selector (Selector | str | None)

Return type:

Shape

class cadquery.Shell(obj: TopoDS_Shape)[source]

Bases: Shape

the outer boundary of a surface

Parameters:

obj (TopoDS_Shape)

classmethod makeShell(listOfFaces: Iterable[Face]) Shell[source]

Makes a shell from faces.

Parameters:

listOfFaces (Iterable[Face])

Return type:

Shell

class cadquery.Sketch(parent: ~typing.Any = None, locs: ~typing.Iterable[~cadquery.occ_impl.geom.Location] = (<cadquery.occ_impl.geom.Location object>, ), obj: ~cadquery.occ_impl.shapes.Compound | None = None)[source]

Bases: object

2D sketch. Supports faces, edges and edges with constraints based construction.

Parameters:
__add__(other: Sketch) T[source]

Fuse self and other.

Parameters:
Return type:

T

__init__(parent: ~typing.Any = None, locs: ~typing.Iterable[~cadquery.occ_impl.geom.Location] = (<cadquery.occ_impl.geom.Location object>, ), obj: ~cadquery.occ_impl.shapes.Compound | None = None)[source]

Construct an empty sketch.

Parameters:
__iter__() Iterator[Face][source]

Iterate over faces-locations combinations. If not faces are present iterate over edges:

Return type:

Iterator[Face]

__mul__(other: Sketch) T[source]

Intersect self and other.

Parameters:
Return type:

T

__sub__(other: Sketch) T[source]

Subtract other from self.

Parameters:
Return type:

T

__truediv__(other: Sketch) T[source]

Split self with other.

Parameters:
Return type:

T

__weakref__

list of weak references to the object (if defined)

add() T[source]

Add selection to the underlying faces.

Parameters:

self (T)

Return type:

T

apply(f: Callable[[Iterable[Shape | Location]], Iterable[Shape | Location]])[source]

Apply a callable to all items at once.

Parameters:
Returns:

Sketch object with f applied to all items.

arc(p2: Vector | Tuple[int | float, int | float], p3: Vector | Tuple[int | float, int | float], tag: str | None = None, forConstruction: bool = False) T[source]
arc(p1: Vector | Tuple[int | float, int | float], p2: Vector | Tuple[int | float, int | float], p3: Vector | Tuple[int | float, int | float], tag: str | None = None, forConstruction: bool = False) T
arc(c: Vector | Tuple[int | float, int | float], r: int | float, a: int | float, da: int | float, tag: str | None = None, forConstruction: bool = False) T

Construct an arc.

Parameters:
  • self (T)

  • p1 (Vector | Tuple[int | float, int | float])

  • p2 (Vector | Tuple[int | float, int | float])

  • p3 (Vector | Tuple[int | float, int | float])

  • tag (str | None)

  • forConstruction (bool)

Return type:

T

assemble(mode: Literal['a', 's', 'i', 'c', 'r'] = 'a', tag: str | None = None) T[source]

Assemble edges into faces.

Parameters:
  • self (T)

  • mode (Literal['a', 's', 'i', 'c', 'r'])

  • tag (str | None)

Return type:

T

bezier(pts: Iterable[Vector | Tuple[int | float, int | float]], tag: str | None = None, forConstruction: bool = False) T[source]

Construct an bezier curve.

The edge will pass through the last points, and the inner points are bezier control points.

Parameters:
  • self (T)

  • pts (Iterable[Vector | Tuple[int | float, int | float]])

  • tag (str | None)

  • forConstruction (bool)

Return type:

T

chamfer(d: int | float) T[source]

Add a chamfer based on current selection.

Parameters:
  • self (T)

  • d (int | float)

Return type:

T

circle(r: int | float, mode: Literal['a', 's', 'i', 'c', 'r'] = 'a', tag: str | None = None) T[source]

Construct a circular face.

Parameters:
  • self (T)

  • r (int | float)

  • mode (Literal['a', 's', 'i', 'c', 'r'])

  • tag (str | None)

Return type:

T

clean() T[source]

Remove internal wires.

Parameters:

self (T)

Return type:

T

close(tag: str | None = None) T[source]

Connect last edge to the first one.

Parameters:
  • self (T)

  • tag (str | None)

Return type:

T

constrain(tag1: str, tag2: str, constraint: Literal['Fixed', 'FixedPoint', 'Coincident', 'Angle', 'Length', 'Distance', 'Radius', 'Orientation', 'ArcAngle'], arg: Any) T[source]
constrain(tag: str, constraint: Literal['Fixed', 'FixedPoint', 'Coincident', 'Angle', 'Length', 'Distance', 'Radius', 'Orientation', 'ArcAngle'], arg: Any) T

Add a constraint.

Parameters:
  • self (T)

  • tag (str)

  • constraint (Literal['Fixed', 'FixedPoint', 'Coincident', 'Angle', 'Length', 'Distance', 'Radius', 'Orientation', 'ArcAngle'])

  • arg (Any)

Return type:

T

copy() T[source]

Create a partial copy of the sketch.

Parameters:

self (T)

Return type:

T

delete() T[source]

Delete selected object.

Parameters:

self (T)

Return type:

T

distribute(n: int, start: int | float = 0, stop: int | float = 1, rotate: bool = True) T[source]

Distribute locations along selected edges or wires.

Parameters:
  • self (T)

  • n (int)

  • start (int | float)

  • stop (int | float)

  • rotate (bool)

Return type:

T

each(callback: Callable[[Location], Face | Sketch | Compound], mode: Literal['a', 's', 'i', 'c', 'r'] = 'a', tag: str | None = None, ignore_selection: bool = False) T[source]

Apply a callback on all applicable entities.

Parameters:
  • self (T)

  • callback (Callable[[Location], Face | Sketch | Compound])

  • mode (Literal['a', 's', 'i', 'c', 'r'])

  • tag (str | None)

  • ignore_selection (bool)

Return type:

T

edge(val: Edge, tag: str | None = None, forConstruction: bool = False) T[source]

Add an edge to the sketch.

Parameters:
  • self (T)

  • val (Edge)

  • tag (str | None)

  • forConstruction (bool)

Return type:

T

edges(s: str | Selector | None = None, tag: str | None = None) T[source]

Select edges.

Parameters:
  • self (T)

  • s (str | Selector | None)

  • tag (str | None)

Return type:

T

ellipse(a1: int | float, a2: int | float, angle: int | float = 0, mode: Literal['a', 's', 'i', 'c', 'r'] = 'a', tag: str | None = None) T[source]

Construct an elliptical face.

Parameters:
  • self (T)

  • a1 (int | float)

  • a2 (int | float)

  • angle (int | float)

  • mode (Literal['a', 's', 'i', 'c', 'r'])

  • tag (str | None)

Return type:

T

export(fname: str, tolerance: float = 0.1, angularTolerance: float = 0.1, opt: Dict[str, Any] | None = None) T[source]

Export Sketch to file.

Parameters:
  • self (T)

  • path – Filename.

  • tolerance (float) – the deflection tolerance, in model units. Default 0.1.

  • angularTolerance (float) – the angular tolerance, in radians. Default 0.1.

  • opt (Dict[str, Any] | None) – additional options passed to the specific exporter. Default None.

  • fname (str)

Returns:

Self.

Return type:

T

face(b: Wire | Iterable[Edge] | Shape | T, angle: int | float = 0, mode: Literal['a', 's', 'i', 'c', 'r'] = 'a', tag: str | None = None, ignore_selection: bool = False) T[source]

Construct a face from a wire or edges.

Parameters:
  • self (T)

  • b (Wire | Iterable[Edge] | Shape | T)

  • angle (int | float)

  • mode (Literal['a', 's', 'i', 'c', 'r'])

  • tag (str | None)

  • ignore_selection (bool)

Return type:

T

faces(s: str | Selector | None = None, tag: str | None = None) T[source]

Select faces.

Parameters:
  • self (T)

  • s (str | Selector | None)

  • tag (str | None)

Return type:

T

fillet(d: int | float) T[source]

Add a fillet based on current selection.

Parameters:
  • self (T)

  • d (int | float)

Return type:

T

filter(f: Callable[[Shape | Location], bool]) T[source]

Filter items using a boolean predicate.

Parameters:
  • self (T)

  • f (Callable[[Shape | Location], bool]) – Callable to be used for filtering.

Returns:

Sketch object with filtered items.

Return type:

T

finalize() Any[source]

Finish sketch construction and return the parent.

Return type:

Any

hull(mode: Literal['a', 's', 'i', 'c', 'r'] = 'a', tag: str | None = None) T[source]

Generate a convex hull from current selection or all objects.

Parameters:
  • self (T)

  • mode (Literal['a', 's', 'i', 'c', 'r'])

  • tag (str | None)

Return type:

T

importDXF(filename: str, tol: float = 1e-06, exclude: List[str] = [], include: List[str] = [], angle: int | float = 0, mode: Literal['a', 's', 'i', 'c', 'r'] = 'a', tag: str | None = None) T[source]

Import a DXF file and construct face(s)

Parameters:
  • self (T)

  • filename (str)

  • tol (float)

  • exclude (List[str])

  • include (List[str])

  • angle (int | float)

  • mode (Literal['a', 's', 'i', 'c', 'r'])

  • tag (str | None)

Return type:

T

invoke(f: Callable[[T], T] | Callable[[T], None] | Callable[[], None])[source]

Invoke a callable mapping Sketch to Sketch or None. Supports also callables that take no arguments such as breakpoint. Returns self if callable returns None.

Parameters:
  • self (T)

  • f (Callable[[T], T] | Callable[[T], None] | Callable[[], None]) – Callable to be invoked.

Returns:

Sketch object.

located(loc: Location) T[source]

Create a partial copy of the sketch with a new location.

Parameters:
Return type:

T

map(f: Callable[[Shape | Location], Shape | Location])[source]

Apply a callable to every item separately.

Parameters:
Returns:

Sketch object with f applied to all items.

moved(loc: Location) T[source]
moved(loc1: Location, loc2: Location, *locs: Location) T
moved(locs: Sequence[Location]) T
moved(x: int | float = 0, y: int | float = 0, z: int | float = 0, rx: int | float = 0, ry: int | float = 0, rz: int | float = 0) T
moved(loc: Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float]) T
moved(loc1: Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float], loc2: Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float], *locs: Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float]) T
moved(loc: Sequence[Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float]]) T

Create a partial copy of the sketch with moved _faces.

offset(d: int | float, mode: Literal['a', 's', 'i', 'c', 'r'] = 'a', tag: str | None = None) T[source]

Offset selected wires or edges.

Parameters:
  • self (T)

  • d (int | float)

  • mode (Literal['a', 's', 'i', 'c', 'r'])

  • tag (str | None)

Return type:

T

parray(r: int | float, a1: int | float, da: int | float, n: int, rotate: bool = True) T[source]

Generate a polar array of locations.

Parameters:
  • self (T)

  • r (int | float)

  • a1 (int | float)

  • da (int | float)

  • n (int)

  • rotate (bool)

Return type:

T

polygon(pts: Iterable[Vector | Tuple[int | float, int | float]], angle: int | float = 0, mode: Literal['a', 's', 'i', 'c', 'r'] = 'a', tag: str | None = None) T[source]

Construct a polygonal face.

Parameters:
  • self (T)

  • pts (Iterable[Vector | Tuple[int | float, int | float]])

  • angle (int | float)

  • mode (Literal['a', 's', 'i', 'c', 'r'])

  • tag (str | None)

Return type:

T

push(locs: Iterable[Location | Vector | Tuple[int | float, int | float]], tag: str | None = None) T[source]

Set current selection to given locations or points.

Parameters:
  • self (T)

  • locs (Iterable[Location | Vector | Tuple[int | float, int | float]])

  • tag (str | None)

Return type:

T

rarray(xs: int | float, ys: int | float, nx: int, ny: int) T[source]

Generate a rectangular array of locations.

Parameters:
  • self (T)

  • xs (int | float)

  • ys (int | float)

  • nx (int)

  • ny (int)

Return type:

T

rect(w: int | float, h: int | float, angle: int | float = 0, mode: Literal['a', 's', 'i', 'c', 'r'] = 'a', tag: str | None = None) T[source]

Construct a rectangular face.

Parameters:
  • self (T)

  • w (int | float)

  • h (int | float)

  • angle (int | float)

  • mode (Literal['a', 's', 'i', 'c', 'r'])

  • tag (str | None)

Return type:

T

regularPolygon(r: int | float, n: int, angle: int | float = 0, mode: Literal['a', 's', 'i', 'c', 'r'] = 'a', tag: str | None = None) T[source]

Construct a regular polygonal face.

Parameters:
  • self (T)

  • r (int | float)

  • n (int)

  • angle (int | float)

  • mode (Literal['a', 's', 'i', 'c', 'r'])

  • tag (str | None)

Return type:

T

replace() T[source]

Replace the underlying faces with the selection.

Parameters:

self (T)

Return type:

T

reset() T[source]

Reset current selection.

Parameters:

self (T)

Return type:

T

segment(p2: Vector | Tuple[int | float, int | float], tag: str | None = None, forConstruction: bool = False) T[source]
segment(p1: Vector | Tuple[int | float, int | float], p2: Vector | Tuple[int | float, int | float], tag: str | None = None, forConstruction: bool = False) T
segment(l: int | float, a: int | float, tag: str | None = None, forConstruction: bool = False) T

Construct a segment.

Parameters:
  • self (T)

  • p1 (Vector | Tuple[int | float, int | float])

  • p2 (Vector | Tuple[int | float, int | float])

  • tag (str | None)

  • forConstruction (bool)

Return type:

T

select(*tags: str) T[source]

Select based on tags.

Parameters:
  • self (T)

  • tags (str)

Return type:

T

slot(w: int | float, h: int | float, angle: int | float = 0, mode: Literal['a', 's', 'i', 'c', 'r'] = 'a', tag: str | None = None) T[source]

Construct a slot-shaped face.

Parameters:
  • self (T)

  • w (int | float)

  • h (int | float)

  • angle (int | float)

  • mode (Literal['a', 's', 'i', 'c', 'r'])

  • tag (str | None)

Return type:

T

solve() T[source]

Solve current constraints and update edge positions.

Parameters:

self (T)

Return type:

T

sort(key: Callable[[Shape | Location], Any]) T[source]

Sort items using a callable.

Parameters:
  • self (T)

  • key (Callable[[Shape | Location], Any]) – Callable to be used for sorting.

Returns:

Sketch object with items sorted.

Return type:

T

spline(pts: Iterable[Vector | Tuple[int | float, int | float]], tangents: Iterable[Vector | Tuple[int | float, int | float]] | None, periodic: bool, tag: str | None = None, forConstruction: bool = False) T[source]
spline(pts: Iterable[Vector | Tuple[int | float, int | float]], tag: str | None = None, forConstruction: bool = False) T

Construct a spline edge.

Parameters:
  • self (T)

  • pts (Iterable[Vector | Tuple[int | float, int | float]])

  • tangents (Iterable[Vector | Tuple[int | float, int | float]] | None)

  • periodic (bool)

  • tag (str | None)

  • forConstruction (bool)

Return type:

T

subtract() T[source]

Subtract selection from the underlying faces.

Parameters:

self (T)

Return type:

T

tag(tag: str) T[source]

Tag current selection.

Parameters:
  • self (T)

  • tag (str)

Return type:

T

trapezoid(w: int | float, h: int | float, a1: int | float, a2: float | None = None, angle: int | float = 0, mode: Literal['a', 's', 'i', 'c', 'r'] = 'a', tag: str | None = None) T[source]

Construct a trapezoidal face.

Parameters:
  • self (T)

  • w (int | float)

  • h (int | float)

  • a1 (int | float)

  • a2 (float | None)

  • angle (int | float)

  • mode (Literal['a', 's', 'i', 'c', 'r'])

  • tag (str | None)

Return type:

T

val() Shape | Location[source]

Return the first selected item, underlying compound or first edge.

Parameters:

self (T)

Return type:

Shape | Location

vals() List[Shape | Location][source]

Return all selected items, underlying compound or all edges.

Parameters:

self (T)

Return type:

List[Shape | Location]

vertices(s: str | Selector | None = None, tag: str | None = None) T[source]

Select vertices.

Parameters:
  • self (T)

  • s (str | Selector | None)

  • tag (str | None)

Return type:

T

wires(s: str | Selector | None = None, tag: str | None = None) T[source]

Select wires.

Parameters:
  • self (T)

  • s (str | Selector | None)

  • tag (str | None)

Return type:

T

class cadquery.Solid(obj: TopoDS_Shape)[source]

Bases: Shape, Mixin3D

a single solid

Parameters:

obj (TopoDS_Shape)

classmethod extrudeLinear(outerWire: Wire, innerWires: List[Wire], vecNormal: Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float], taper: float | int = 0) Solid[source]
classmethod extrudeLinear(face: Face, vecNormal: Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float], taper: float | int = 0) Solid

Attempt to extrude the list of wires into a prismatic solid in the provided direction

Parameters:
  • outerWire (Wire) – the outermost wire

  • innerWires (List[Wire]) – a list of inner wires

  • vecNormal (Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float]) – a vector along which to extrude the wires

  • taper (float | int) – taper angle, default=0

Returns:

a Solid object

Return type:

Solid

The wires must not intersect

Extruding wires is very non-trivial. Nested wires imply very different geometry, and there are many geometries that are invalid. In general, the following conditions must be met:

  • all wires must be closed

  • there cannot be any intersecting or self-intersecting wires

  • wires must be listed from outside in

  • more than one levels of nesting is not supported reliably

This method will attempt to sort the wires, but there is much work remaining to make this method reliable.

classmethod extrudeLinearWithRotation(outerWire: Wire, innerWires: List[Wire], vecCenter: Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float], vecNormal: Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float], angleDegrees: float | int) Solid[source]
classmethod extrudeLinearWithRotation(face: Face, vecCenter: Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float], vecNormal: Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float], angleDegrees: float | int) Solid

Creates a ‘twisted prism’ by extruding, while simultaneously rotating around the extrusion vector.

Though the signature may appear to be similar enough to extrudeLinear to merit combining them, the construction methods used here are different enough that they should be separate.

At a high level, the steps followed are:

  1. accept a set of wires

  2. create another set of wires like this one, but which are transformed and rotated

  3. create a ruledSurface between the sets of wires

  4. create a shell and compute the resulting object

Parameters:
  • outerWire (Wire) – the outermost wire

  • innerWires (List[Wire]) – a list of inner wires

  • vecCenter (Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float]) – the center point about which to rotate. the axis of rotation is defined by vecNormal, located at vecCenter.

  • vecNormal (Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float]) – a vector along which to extrude the wires

  • angleDegrees (float | int) – the angle to rotate through while extruding

Returns:

a Solid object

Return type:

Solid

innerShells() List[Shell][source]

Returns inner shells.

Return type:

List[Shell]

classmethod interpPlate(surf_edges, surf_pts, thickness, degree=3, nbPtsOnCur=15, nbIter=2, anisotropy=False, tol2d=1e-05, tol3d=0.0001, tolAng=0.01, tolCurv=0.1, maxDeg=8, maxSegments=9) Solid | Face[source]

Returns a plate surface that is ‘thickness’ thick, enclosed by ‘surf_edge_pts’ points, and going through ‘surf_pts’ points.

Parameters:
  • surf_edges – list of [x,y,z] float ordered coordinates or list of ordered or unordered wires

  • surf_pts – list of [x,y,z] float coordinates (uses only edges if [])

  • thickness – thickness may be negative or positive depending on direction, (returns 2D surface if 0)

  • degree – >=2

  • nbPtsOnCur – number of points on curve >= 15

  • nbIter – number of iterations >= 2

  • anisotropy – bool Anisotropy

  • tol2d – 2D tolerance >0

  • tol3d – 3D tolerance >0

  • tolAng – angular tolerance

  • tolCurv – tolerance for curvature >0

  • maxDeg – highest polynomial degree >= 2

  • maxSegments – greatest number of segments >= 2

Return type:

Solid | Face

static isSolid(obj: Shape) bool[source]

Returns true if the object is a solid, false otherwise

Parameters:

obj (Shape)

Return type:

bool

classmethod makeBox(length,width,height,[pnt,dir]) -- Make a box located in pnt with the dimensions (length,width,height)[source]

By default pnt=Vector(0,0,0) and dir=Vector(0,0,1)

Parameters:
  • length (float)

  • width (float)

  • height (float)

  • pnt (Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float])

  • dir (Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float])

Return type:

Solid

classmethod makeCone(radius1: float, radius2: float, height: float, pnt: ~cadquery.occ_impl.geom.Vector | ~typing.Tuple[int | float, int | float] | ~typing.Tuple[int | float, int | float, int | float] = Vector: (0.0, 0.0, 0.0), dir: ~cadquery.occ_impl.geom.Vector | ~typing.Tuple[int | float, int | float] | ~typing.Tuple[int | float, int | float, int | float] = Vector: (0.0, 0.0, 1.0), angleDegrees: float = 360) Solid[source]

Make a cone with given radii and height By default pnt=Vector(0,0,0), dir=Vector(0,0,1) and angle=360

Parameters:
  • radius1 (float)

  • radius2 (float)

  • height (float)

  • pnt (Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float])

  • dir (Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float])

  • angleDegrees (float)

Return type:

Solid

classmethod makeCylinder(radius: float, height: float, pnt: ~cadquery.occ_impl.geom.Vector | ~typing.Tuple[int | float, int | float] | ~typing.Tuple[int | float, int | float, int | float] = Vector: (0.0, 0.0, 0.0), dir: ~cadquery.occ_impl.geom.Vector | ~typing.Tuple[int | float, int | float] | ~typing.Tuple[int | float, int | float, int | float] = Vector: (0.0, 0.0, 1.0), angleDegrees: float = 360) Solid[source]

makeCylinder(radius,height,[pnt,dir,angle]) – Make a cylinder with a given radius and height By default pnt=Vector(0,0,0),dir=Vector(0,0,1) and angle=360

Parameters:
  • radius (float)

  • height (float)

  • pnt (Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float])

  • dir (Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float])

  • angleDegrees (float)

Return type:

Solid

classmethod makeLoft(listOfWire: List[Wire], ruled: bool = False) Solid[source]

makes a loft from a list of wires The wires will be converted into faces when possible– it is presumed that nobody ever actually wants to make an infinitely thin shell for a real FreeCADPart.

Parameters:
  • listOfWire (List[Wire])

  • ruled (bool)

Return type:

Solid

classmethod makeSolid(shell: Shell) Solid[source]

Makes a solid from a single shell.

Parameters:

shell (Shell)

Return type:

Solid

classmethod makeSphere(radius: float, pnt: ~cadquery.occ_impl.geom.Vector | ~typing.Tuple[int | float, int | float] | ~typing.Tuple[int | float, int | float, int | float] = Vector: (0.0, 0.0, 0.0), dir: ~cadquery.occ_impl.geom.Vector | ~typing.Tuple[int | float, int | float] | ~typing.Tuple[int | float, int | float, int | float] = Vector: (0.0, 0.0, 1.0), angleDegrees1: float = 0, angleDegrees2: float = 90, angleDegrees3: float = 360) Shape[source]

Make a sphere with a given radius By default pnt=Vector(0,0,0), dir=Vector(0,0,1), angle1=0, angle2=90 and angle3=360

Parameters:
  • radius (float)

  • pnt (Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float])

  • dir (Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float])

  • angleDegrees1 (float)

  • angleDegrees2 (float)

  • angleDegrees3 (float)

Return type:

Shape

classmethod makeTorus(radius1: float, radius2: float, pnt: ~cadquery.occ_impl.geom.Vector | ~typing.Tuple[int | float, int | float] | ~typing.Tuple[int | float, int | float, int | float] = Vector: (0.0, 0.0, 0.0), dir: ~cadquery.occ_impl.geom.Vector | ~typing.Tuple[int | float, int | float] | ~typing.Tuple[int | float, int | float, int | float] = Vector: (0.0, 0.0, 1.0), angleDegrees1: float = 0, angleDegrees2: float = 360) Solid[source]

makeTorus(radius1,radius2,[pnt,dir,angle1,angle2,angle]) – Make a torus with a given radii and angles By default pnt=Vector(0,0,0),dir=Vector(0,0,1),angle1=0 ,angle1=360 and angle=360

Parameters:
  • radius1 (float)

  • radius2 (float)

  • pnt (Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float])

  • dir (Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float])

  • angleDegrees1 (float)

  • angleDegrees2 (float)

Return type:

Solid

classmethod makeWedge(dx: float, dy: float, dz: float, xmin: float, zmin: float, xmax: float, zmax: float, pnt: ~cadquery.occ_impl.geom.Vector | ~typing.Tuple[int | float, int | float] | ~typing.Tuple[int | float, int | float, int | float] = Vector: (0.0, 0.0, 0.0), dir: ~cadquery.occ_impl.geom.Vector | ~typing.Tuple[int | float, int | float] | ~typing.Tuple[int | float, int | float, int | float] = Vector: (0.0, 0.0, 1.0)) Solid[source]

Make a wedge located in pnt By default pnt=Vector(0,0,0) and dir=Vector(0,0,1)

Parameters:
  • dx (float)

  • dy (float)

  • dz (float)

  • xmin (float)

  • zmin (float)

  • xmax (float)

  • zmax (float)

  • pnt (Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float])

  • dir (Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float])

Return type:

Solid

outerShell() Shell[source]

Returns outer shell.

Return type:

Shell

classmethod revolve(outerWire: Wire, innerWires: List[Wire], angleDegrees: float | int, axisStart: Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float], axisEnd: Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float]) Solid[source]
classmethod revolve(face: Face, angleDegrees: float | int, axisStart: Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float], axisEnd: Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float]) Solid

Attempt to revolve the list of wires into a solid in the provided direction

Parameters:
  • outerWire (Wire) – the outermost wire

  • innerWires (List[Wire]) – a list of inner wires

  • angleDegrees (float, anything less than 360 degrees will leave the shape open) – the angle to revolve through.

  • axisStart (Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float]) – the start point of the axis of rotation

  • axisEnd (Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float]) – the end point of the axis of rotation

Returns:

a Solid object

Return type:

Solid

The wires must not intersect

  • all wires must be closed

  • there cannot be any intersecting or self-intersecting wires

  • wires must be listed from outside in

  • more than one levels of nesting is not supported reliably

  • the wire(s) that you’re revolving cannot be centered

This method will attempt to sort the wires, but there is much work remaining to make this method reliable.

classmethod sweep(face: Face, path: Wire | Edge, makeSolid: bool = True, isFrenet: bool = False, mode: Vector | Wire | Edge | None = None, transitionMode: Literal['transformed', 'round', 'right'] = 'transformed') Shape[source]
classmethod sweep(outerWire: Wire, innerWires: List[Wire], path: Wire | Edge, makeSolid: bool = True, isFrenet: bool = False, mode: Vector | Wire | Edge | None = None, transitionMode: Literal['transformed', 'round', 'right'] = 'transformed') Shape

Attempt to sweep the list of wires into a prismatic solid along the provided path

Parameters:
  • outerWire (Wire) – the outermost wire

  • innerWires (List[Wire]) – a list of inner wires

  • path (Wire | Edge) – The wire to sweep the face resulting from the wires over

  • makeSolid (bool) – return Solid or Shell (default True)

  • isFrenet (bool) – Frenet mode (default False)

  • mode (Vector | Wire | Edge | None) – additional sweep mode parameters

  • transitionMode (Literal['transformed', 'round', 'right']) – handling of profile orientation at C1 path discontinuities. Possible values are {‘transformed’,’round’, ‘right’} (default: ‘right’).

Returns:

a Solid object

Return type:

Shape

classmethod sweep_multi(profiles: Iterable[Wire | Face], path: Wire | Edge, makeSolid: bool = True, isFrenet: bool = False, mode: Vector | Wire | Edge | None = None) Solid[source]

Multi section sweep. Only single outer profile per section is allowed.

Parameters:
  • profiles (Iterable[Wire | Face]) – list of profiles

  • path (Wire | Edge) – The wire to sweep the face resulting from the wires over

  • mode (Vector | Wire | Edge | None) – additional sweep mode parameters.

  • makeSolid (bool)

  • isFrenet (bool)

Returns:

a Solid object

Return type:

Solid

class cadquery.StringSyntaxSelector(selectorString)[source]

Bases: Selector

Filter lists objects using a simple string syntax. All of the filters available in the string syntax are also available ( usually with more functionality ) through the creation of full-fledged selector objects. see Selector and its subclasses

Filtering works differently depending on the type of object list being filtered.

Parameters:

selectorString – A two-part selector string, [selector][axis]

Returns:

objects that match the specified selector

*Modifiers* are ('|','+','-','<','>','%')

|:

parallel to ( same as ParallelDirSelector ). Can return multiple objects.

#:

perpendicular to (same as PerpendicularDirSelector )

+:

positive direction (same as DirectionSelector )

-:

negative direction (same as DirectionSelector )

>:

maximize (same as DirectionMinMaxSelector with directionMax=True)

<:

minimize (same as DirectionMinMaxSelector with directionMax=False )

%:

curve/surface type (same as TypeSelector)

*axisStrings* are: X,Y,Z,XY,YZ,XZ or (x,y,z) which defines an arbitrary direction

It is possible to combine simple selectors together using logical operations. The following operations are supported

and:

Logical AND, e.g. >X and >Y

or:

Logical OR, e.g. |X or |Y

not:

Logical NOT, e.g. not #XY

exc(ept):

Set difference (equivalent to AND NOT): |X exc >Z

Finally, it is also possible to use even more complex expressions with nesting and arbitrary number of terms, e.g.

(not >X[0] and #XY) or >XY[0]

Selectors are a complex topic: see Selectors Reference for more information

__init__(selectorString)[source]

Feed the input string through the parser and construct an relevant complex selector object

filter(objectList: Sequence[Shape])[source]

Filter give object list through th already constructed complex selector object

Parameters:

objectList (Sequence[Shape])

class cadquery.TypeSelector(typeString: str)[source]

Bases: Selector

Selects objects having the prescribed geometry type.

Applicability:

Faces: PLANE, CYLINDER, CONE, SPHERE, TORUS, BEZIER, BSPLINE, REVOLUTION, EXTRUSION, OFFSET, OTHER Edges: LINE, CIRCLE, ELLIPSE, HYPERBOLA, PARABOLA, BEZIER, BSPLINE, OFFSET, OTHER

You can use the string selector syntax. For example this:

CQ(aCube).faces(TypeSelector("PLANE"))

will select 6 faces, and is equivalent to:

CQ(aCube).faces("%PLANE")
Parameters:

typeString (str)

__init__(typeString: str)[source]
Parameters:

typeString (str)

filter(objectList: Sequence[Shape]) List[Shape][source]

Filter the provided list.

The default implementation returns the original list unfiltered.

Parameters:

objectList (list of OCCT primitives) – list to filter

Returns:

filtered list

Return type:

List[Shape]

class cadquery.Vector(x: float, y: float, z: float)[source]
class cadquery.Vector(x: float, y: float)
class cadquery.Vector(v: Vector)
class cadquery.Vector(v: Sequence[float])
class cadquery.Vector(v: gp_Vec | gp_Pnt | gp_Dir | gp_XYZ)
class cadquery.Vector

Bases: object

Create a 3-dimensional vector

Parameters:

args – a 3D vector, with x-y-z parts.

you can either provide:
  • nothing (in which case the null vector is return)

  • a gp_Vec

  • a vector ( in which case it is copied )

  • a 3-tuple

  • a 2-tuple (z assumed to be 0)

  • three float values: x, y, and z

  • two float values: x,y

Center() Vector[source]

Return the vector itself

The center of myself is myself. Provided so that vectors, vertices, and other shapes all support a common interface, when Center() is requested for all objects on the stack.

Return type:

Vector

__eq__(other: Vector) bool[source]

Return self==value.

Parameters:

other (Vector)

Return type:

bool

__hash__ = None
__init__(x: float, y: float, z: float) None[source]
__init__(x: float, y: float) None
__init__(v: Vector) None
__init__(v: Sequence[float]) None
__init__(v: gp_Vec | gp_Pnt | gp_Dir | gp_XYZ) None
__init__() None
__repr__() str[source]

Return repr(self).

Return type:

str

__str__() str[source]

Return str(self).

Return type:

str

__weakref__

list of weak references to the object (if defined)

multiply(scale: float) Vector[source]

Return a copy multiplied by the provided scalar

Parameters:

scale (float)

Return type:

Vector

normalized() Vector[source]

Return a normalized version of this vector

Return type:

Vector

projectToLine(line: Vector) Vector[source]

Returns a new vector equal to the projection of this Vector onto the line represented by Vector <line>

Parameters:
  • args – Vector

  • line (Vector)

Return type:

Vector

Returns the projected vector.

projectToPlane(plane: Plane) Vector[source]

Vector is projected onto the plane provided as input.

Parameters:
  • args – Plane object

  • plane (Plane)

Return type:

Vector

Returns the projected vector.

class cadquery.Vertex(obj: TopoDS_Shape, forConstruction: bool = False)[source]

Bases: Shape

A Single Point in Space

Parameters:
  • obj (TopoDS_Shape)

  • forConstruction (bool)

Center() Vector[source]

The center of a vertex is itself!

Return type:

Vector

__init__(obj: TopoDS_Shape, forConstruction: bool = False)[source]

Create a vertex

Parameters:
  • obj (TopoDS_Shape)

  • forConstruction (bool)

class cadquery.Wire(obj: TopoDS_Shape)[source]

Bases: Shape, Mixin1D

A series of connected, ordered Edges, that typically bounds a Face

Parameters:

obj (TopoDS_Shape)

Vertices() List[Vertex][source]

Ordered list of vertices of the wire.

Return type:

List[Vertex]

__iter__() Iterator[Edge][source]

Iterate over edges in an ordered way.

Return type:

Iterator[Edge]

classmethod assembleEdges(listOfEdges: Iterable[Edge]) Wire[source]

Attempts to build a wire that consists of the edges in the provided list

Parameters:
  • cls

  • listOfEdges (Iterable[Edge]) – a list of Edge objects. The edges are not to be consecutive.

Returns:

a wire with the edges assembled

Return type:

Wire

BRepBuilderAPI_MakeWire::Error() values:

  • BRepBuilderAPI_WireDone = 0

  • BRepBuilderAPI_EmptyWire = 1

  • BRepBuilderAPI_DisconnectedWire = 2

  • BRepBuilderAPI_NonManifoldWire = 3

chamfer2D(d: float, vertices: Iterable[Vertex]) Wire[source]

Apply 2D chamfer to a wire

Parameters:
  • d (float)

  • vertices (Iterable[Vertex])

Return type:

Wire

close() Wire[source]

Close a Wire

Return type:

Wire

classmethod combine(listOfWires: Iterable[Wire | Edge], tol: float = 1e-09) List[Wire][source]

Attempt to combine a list of wires and edges into a new wire.

Parameters:
  • cls

  • listOfWires (Iterable[Wire | Edge])

  • tol (float) – default 1e-9

Returns:

List[Wire]

Return type:

List[Wire]

fillet(radius: float, vertices: Iterable[Vertex] | None = None) Wire[source]

Apply 2D or 3D fillet to a wire

Parameters:
  • radius (float) – the radius of the fillet, must be > zero

  • vertices (Iterable[Vertex] | None) – the vertices to delete (where the fillet will be applied). By default all vertices are deleted except ends of open wires.

Returns:

A wire with filleted corners

Return type:

Wire

fillet2D(radius: float, vertices: Iterable[Vertex]) Wire[source]

Apply 2D fillet to a wire

Parameters:
  • radius (float)

  • vertices (Iterable[Vertex])

Return type:

Wire

classmethod makeCircle(radius: float, center: Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float], normal: Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float]) Wire[source]

Makes a Circle centered at the provided point, having normal in the provided direction

Parameters:
  • radius (float) – floating point radius of the circle, must be > 0

  • center (Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float]) – vector representing the center of the circle

  • normal (Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float]) – vector representing the direction of the plane the circle should lie in

Return type:

Wire

classmethod makeEllipse(x_radius: float, y_radius: float, center: Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float], normal: Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float], xDir: Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float], angle1: float = 360.0, angle2: float = 360.0, rotation_angle: float = 0.0, closed: bool = True) Wire[source]

Makes an Ellipse centered at the provided point, having normal in the provided direction

Parameters:
  • x_radius (float) – floating point major radius of the ellipse (x-axis), must be > 0

  • y_radius (float) – floating point minor radius of the ellipse (y-axis), must be > 0

  • center (Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float]) – vector representing the center of the circle

  • normal (Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float]) – vector representing the direction of the plane the circle should lie in

  • angle1 (float) – start angle of arc

  • angle2 (float) – end angle of arc

  • rotation_angle (float) – angle to rotate the created ellipse / arc

  • xDir (Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float])

  • closed (bool)

Return type:

Wire

classmethod makeHelix(pitch: float, height: float, radius: float, center: ~cadquery.occ_impl.geom.Vector | ~typing.Tuple[int | float, int | float] | ~typing.Tuple[int | float, int | float, int | float] = Vector: (0.0, 0.0, 0.0), dir: ~cadquery.occ_impl.geom.Vector | ~typing.Tuple[int | float, int | float] | ~typing.Tuple[int | float, int | float, int | float] = Vector: (0.0, 0.0, 1.0), angle: float = 360.0, lefthand: bool = False) Wire[source]

Make a helix with a given pitch, height and radius By default a cylindrical surface is used to create the helix. If the fourth parameter is set (the apex given in degree) a conical surface is used instead’

Parameters:
  • pitch (float)

  • height (float)

  • radius (float)

  • center (Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float])

  • dir (Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float])

  • angle (float)

  • lefthand (bool)

Return type:

Wire

classmethod makePolygon(listOfVertices: Iterable[Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float]], forConstruction: bool = False, close: bool = False) Wire[source]

Construct a polygonal wire from points.

Parameters:
  • listOfVertices (Iterable[Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float]])

  • forConstruction (bool)

  • close (bool)

Return type:

Wire

offset2D(d: float, kind: Literal['arc', 'intersection', 'tangent'] = 'arc') List[Wire][source]

Offsets a planar wire

Parameters:
  • d (float)

  • kind (Literal['arc', 'intersection', 'tangent'])

Return type:

List[Wire]

stitch(other: Wire) Wire[source]

Attempt to stitch wires

Parameters:

other (Wire)

Return type:

Wire

class cadquery.Workplane(obj: Vector | Location | Shape | Sketch)[source]
class cadquery.Workplane(inPlane: Plane | str = 'XY', origin: Tuple[float, float] | Tuple[float, float, float] | Vector = (0, 0, 0), obj: Vector | Location | Shape | Sketch | None = None)

Bases: object

Defines a coordinate system in space, in which 2D coordinates can be used.

Parameters:
  • plane (a Plane object, or a string in (XY|YZ|XZ|front|back|top|bottom|left|right)) – the plane in which the workplane will be done

  • origin (a 3-tuple in global coordinates, or None to default to the origin) – the desired origin of the new workplane

  • obj (a CAD primitive, or None to use the centerpoint of the plane as the initial stack value.) – an object to use initially for the stack

Raises:

ValueError if the provided plane is not a plane, a valid named workplane

Returns:

A Workplane object, with coordinate system matching the supplied plane.

The most common use is:

s = Workplane("XY")

After creation, the stack contains a single point, the origin of the underlying plane, and the current point is on the origin.

Note

You can also create workplanes on the surface of existing faces using workplane()

__add__(other: Workplane | Solid | Compound) T[source]

Syntactic sugar for union.

Notice that r = a + b is equivalent to r = a.union(b) and r = a | b.

Parameters:
Return type:

T

__and__(other: Workplane | Solid | Compound) T[source]

Syntactic sugar for intersect.

Notice that r = a & b is equivalent to r = a.intersect(b).

Example:

Box = Workplane("XY").box(1, 1, 1, centered=(False, False, False))
Sphere = Workplane("XY").sphere(1)
result = Box & Sphere
Parameters:
Return type:

T

__init__(obj: Vector | Location | Shape | Sketch) None[source]
__init__(inPlane: Plane | str = 'XY', origin: Tuple[float, float] | Tuple[float, float, float] | Vector = (0, 0, 0), obj: Vector | Location | Shape | Sketch | None = None) None

make a workplane from a particular plane

Parameters:
  • inPlane (a Plane object, or a string in (XY|YZ|XZ|front|back|top|bottom|left|right)) – the plane in which the workplane will be done

  • origin (a 3-tuple in global coordinates, or None to default to the origin) – the desired origin of the new workplane

  • obj (a CAD primitive, or None to use the centerpoint of the plane as the initial stack value.) – an object to use initially for the stack

Raises:

ValueError if the provided plane is not a plane, or one of XY|YZ|XZ

Returns:

A Workplane object, with coordinate system matching the supplied plane.

The most common use is:

s = Workplane("XY")

After creation, the stack contains a single point, the origin of the underlying plane, and the current point is on the origin.

__iter__() Iterator[Shape][source]

Special method for iterating over Shapes in objects

Parameters:

self (T)

Return type:

Iterator[Shape]

__mul__(other: Workplane | Solid | Compound) T[source]

Syntactic sugar for intersect.

Notice that r = a * b is equivalent to r = a.intersect(b).

Example:

Box = Workplane("XY").box(1, 1, 1, centered=(False, False, False))
Sphere = Workplane("XY").sphere(1)
result = Box * Sphere
Parameters:
Return type:

T

__or__(other: Workplane | Solid | Compound) T[source]

Syntactic sugar for union.

Notice that r = a | b is equivalent to r = a.union(b) and r = a + b.

Example:

Box = Workplane("XY").box(1, 1, 1, centered=(False, False, False))
Sphere = Workplane("XY").sphere(1)
result = Box | Sphere
Parameters:
Return type:

T

__sub__(other: Workplane | Solid | Compound) T[source]

Syntactic sugar for cut.

Notice that r = a - b is equivalent to r = a.cut(b).

Example:

Box = Workplane("XY").box(1, 1, 1, centered=(False, False, False))
Sphere = Workplane("XY").sphere(1)
result = Box - Sphere
Parameters:
Return type:

T

__truediv__(other: Workplane | Solid | Compound) T[source]

Syntactic sugar for intersect.

Notice that r = a / b is equivalent to r = a.split(b).

Example:

Box = Workplane("XY").box(1, 1, 1, centered=(False, False, False))
Sphere = Workplane("XY").sphere(1)
result = Box / Sphere
Parameters:
Return type:

T

__weakref__

list of weak references to the object (if defined)

add(obj: Workplane) T[source]
add(obj: Vector | Location | Shape | Sketch) T
add(obj: Iterable[Vector | Location | Shape | Sketch]) T

Adds an object or a list of objects to the stack

Parameters:

obj (a Workplane, CAD primitive, or list of CAD primitives) – an object to add

Returns:

a Workplane with the requested operation performed

If a Workplane object, the values of that object’s stack are added. If a list of cad primitives, they are all added. If a single CAD primitive then it is added.

Used in rare cases when you need to combine the results of several CQ results into a single Workplane object.

all() List[T][source]

Return a list of all CQ objects on the stack.

useful when you need to operate on the elements individually.

Contrast with vals, which returns the underlying objects for all of the items on the stack

Parameters:

self (T)

Return type:

List[T]

ancestors(kind: Literal['Vertex', 'Edge', 'Wire', 'Face', 'Shell', 'Solid', 'CompSolid', 'Compound'], tag: str | None = None) T[source]

Select topological ancestors.

Parameters:
  • self (T)

  • kind (Literal['Vertex', 'Edge', 'Wire', 'Face', 'Shell', 'Solid', 'CompSolid', 'Compound']) – kind of ancestor, e.g. “Face” or “Edge”

  • tag (str | None) – if set, search the tagged object instead of self

Returns:

a Workplane object whose stack contains selected ancestors.

Return type:

T

apply(f: Callable[[Iterable[Vector | Location | Shape | Sketch]], Iterable[Vector | Location | Shape | Sketch]]) T[source]

Apply a callable to all items at once.

Parameters:
Returns:

Workplane object with f applied to all items.

Return type:

T

bezier(listOfXYTuple: Iterable[Tuple[float, float] | Tuple[float, float, float] | Vector], forConstruction: bool = False, includeCurrent: bool = False, makeWire: bool = False) T[source]

Make a cubic Bézier curve by the provided points (2D or 3D).

Parameters:
  • self (T)

  • listOfXYTuple (Iterable[Tuple[float, float] | Tuple[float, float, float] | Vector]) – Bezier control points and end point. All points except the last point are Bezier control points, and the last point is the end point

  • includeCurrent (bool) – Use the current point as a starting point of the curve

  • makeWire (bool) – convert the resulting bezier edge to a wire

  • forConstruction (bool)

Returns:

a Workplane object with the current point at the end of the bezier

Return type:

T

The Bézier Will begin at either current point or the first point of listOfXYTuple, and end with the last point of listOfXYTuple

box(length: float, width: float, height: float, centered: bool | Tuple[bool, bool, bool] = True, combine: bool | Literal['cut', 'a', 's'] = True, clean: bool = True) T[source]

Return a 3d box with specified dimensions for each object on the stack.

Parameters:
  • self (T)

  • length (float) – box size in X direction

  • width (float) – box size in Y direction

  • height (float) – box size in Z direction

  • centered (bool | Tuple[bool, bool, bool]) – If True, the box will be centered around the reference point. If False, the corner of the box will be on the reference point and it will extend in the positive x, y and z directions. Can also use a 3-tuple to specify centering along each axis.

  • combine (bool | Literal['cut', 'a', 's']) – should the results be combined with other solids on the stack (and each other)?

  • clean (bool) – call clean() afterwards to have a clean shape

Return type:

T

One box is created for each item on the current stack. If no items are on the stack, one box using the current workplane center is created.

If combine is true, the result will be a single object on the stack. If a solid was found in the chain, the result is that solid with all boxes produced fused onto it otherwise, the result is the combination of all the produced boxes.

If combine is false, the result will be a list of the boxes produced.

Most often boxes form the basis for a part:

# make a single box with lower left corner at origin
s = Workplane().box(1, 2, 3, centered=False)

But sometimes it is useful to create an array of them:

# create 4 small square bumps on a larger base plate:
s = (
    Workplane()
    .box(4, 4, 0.5)
    .faces(">Z")
    .workplane()
    .rect(3, 3, forConstruction=True)
    .vertices()
    .box(0.25, 0.25, 0.25, combine=True)
)
cboreHole(diameter: float, cboreDiameter: float, cboreDepth: float, depth: float | None = None, clean: bool = True) T[source]

Makes a counterbored hole for each item on the stack.

Parameters:
  • self (T)

  • diameter (float) – the diameter of the hole

  • cboreDiameter (float) – the diameter of the cbore, must be greater than hole diameter

  • cboreDepth (float > 0) – depth of the counterbore

  • depth (float > 0 or None to drill thru the entire part) – the depth of the hole

  • clean (bool) – call clean() afterwards to have a clean shape

Return type:

T

The surface of the hole is at the current workplane plane.

One hole is created for each item on the stack. A very common use case is to use a construction rectangle to define the centers of a set of holes, like so:

s = (
    Workplane()
    .box(2, 4, 0.5)
    .faces(">Z")
    .workplane()
    .rect(1.5, 3.5, forConstruction=True)
    .vertices()
    .cboreHole(0.125, 0.25, 0.125, depth=None)
)

This sample creates a plate with a set of holes at the corners.

Plugin Note: this is one example of the power of plugins. Counterbored holes are quite time consuming to create, but are quite easily defined by users.

see cskHole() to make countersinks instead of counterbores

center(x: float, y: float) T[source]

Shift local coordinates to the specified location.

The location is specified in terms of local coordinates.

Parameters:
  • self (T)

  • x (float) – the new x location

  • y (float) – the new y location

Returns:

the Workplane object, with the center adjusted.

Return type:

T

The current point is set to the new center. This method is useful to adjust the center point after it has been created automatically on a face, but not where you’d like it to be.

In this example, we adjust the workplane center to be at the corner of a cube, instead of the center of a face, which is the default:

# this workplane is centered at x=0.5,y=0.5, the center of the upper face
s = Workplane().box(1, 1, 1).faces(">Z").workplane()

s = s.center(-0.5, -0.5)  # move the center to the corner
t = s.circle(0.25).extrude(0.2)
assert t.faces().size() == 9  # a cube with a cylindrical nub at the top right corner

The result is a cube with a round boss on the corner

chamfer(length: float, length2: float | None = None) T[source]

Chamfers a solid on the selected edges.

The edges on the stack are chamfered. The solid to which the edges belong must be in the parent chain of the selected edges.

Optional parameter length2 can be supplied with a different value than length for a chamfer that is shorter on one side longer on the other side.

Parameters:
  • self (T)

  • length (float) – the length of the chamfer, must be greater than zero

  • length2 (float | None) – optional parameter for asymmetrical chamfer

Raises:
  • ValueError – if at least one edge is not selected

  • ValueError – if the solid containing the edge is not in the chain

Returns:

CQ object with the resulting solid selected.

Return type:

T

This example will create a unit cube, with the top edges chamfered:

s = Workplane("XY").box(1, 1, 1).faces("+Z").chamfer(0.1)

This example will create chamfers longer on the sides:

s = Workplane("XY").box(1, 1, 1).faces("+Z").chamfer(0.2, 0.1)
circle(radius: float, forConstruction: bool = False) T[source]

Make a circle for each item on the stack.

Parameters:
  • self (T)

  • radius (float) – radius of the circle

  • forConstruction (true if the wires are for reference, false if they are creating part geometry) – should the new wires be reference geometry only?

Returns:

a new CQ object with the created wires on the stack

Return type:

T

A common use case is to use a for-construction rectangle to define the centers of a hole pattern:

s = Workplane().rect(4.0, 4.0, forConstruction=True).vertices().circle(0.25)

Creates 4 circles at the corners of a square centered on the origin. Another common case is to use successive circle() calls to create concentric circles. This works because the center of a circle is its reference point:

s = Workplane().circle(2.0).circle(1.0)

Creates two concentric circles, which when extruded will form a ring.

Future Enhancements:

better way to handle forConstruction project points not in the workplane plane onto the workplane plane

clean() T[source]

Cleans the current solid by removing unwanted edges from the faces.

Normally you don’t have to call this function. It is automatically called after each related operation. You can disable this behavior with clean=False parameter if method has any. In some cases this can improve performance drastically but is generally dis-advised since it may break some operations such as fillet.

Note that in some cases where lots of solid operations are chained, clean() may actually improve performance since the shape is ‘simplified’ at each step and thus next operation is easier.

Also note that, due to limitation of the underlying engine, clean may fail to produce a clean output in some cases such as spherical faces.

Parameters:

self (T)

Return type:

T

close() T[source]

End construction, and attempt to build a closed wire.

Returns:

a CQ object with a completed wire on the stack, if possible.

Parameters:

self (T)

Return type:

T

After 2D (or 3D) drafting with methods such as lineTo, threePointArc, tangentArcPoint and polyline, it is necessary to convert the edges produced by these into one or more wires.

When a set of edges is closed, CadQuery assumes it is safe to build the group of edges into a wire. This example builds a simple triangular prism:

s = Workplane().lineTo(1, 0).lineTo(1, 1).close().extrude(0.2)
combine(clean: bool = True, glue: bool = False, tol: float | None = None) T[source]

Attempts to combine all of the items on the stack into a single item.

WARNING: all of the items must be of the same type!

Parameters:
  • self (T)

  • clean (bool) – call clean() afterwards to have a clean shape

  • glue (bool) – use a faster gluing mode for non-overlapping shapes (default False)

  • tol (float | None) – tolerance value for fuzzy bool operation mode (default None)

Raises:

ValueError if there are no items on the stack, or if they cannot be combined

Returns:

a CQ object with the resulting object selected

Return type:

T

combineSolids(otherCQToCombine: Workplane | None = None) Workplane[source]

!!!DEPRECATED!!! use union() Combines all solids on the current stack, and any context object, together into a single object.

After the operation, the returned solid is also the context solid.

Parameters:

otherCQToCombine (Workplane | None) – another CadQuery to combine.

Returns:

a CQ object with the resulting combined solid on the stack.

Return type:

Workplane

Most of the time, both objects will contain a single solid, which is combined and returned on the stack of the new object.

compounds(selector: str | Selector | None = None, tag: str | None = None) T[source]

Select compounds on the stack, optionally filtering the selection. If there are multiple objects on the stack, they are collected and a list of all the distinct compounds is returned.

Parameters:
  • self (T)

  • selector (str | Selector | None) – optional Selector object, or string selector expression (see StringSyntaxSelector)

  • tag (str | None) – if set, search the tagged object instead of self

Returns:

a CQ object whose stack contains all of the distinct compounds of all objects on the current stack, filtered by the provided selector.

Return type:

T

A compound contains multiple CAD primitives that resulted from a single operation, such as a union, cut, split, or fillet. Compounds can contain multiple edges, wires, or solids.

consolidateWires() T[source]

Attempt to consolidate wires on the stack into a single. If possible, a new object with the results are returned. if not possible, the wires remain separated

Parameters:

self (T)

Return type:

T

<