CadQuery API Reference¶
The CadQuery API is made up of 3 main objects:
- CQ - An object that wraps a topological entity.
- Workplane – A subclass of CQ, that applies in a 2-D modelling context.
- Selector – Filter and select things
This page lists methods of these objects grouped by functional area
See also
This page lists api methods grouped by functional area. Use CadQuery Class Summary to see methods alphabetically by class.
Initialization¶
Creating new workplanes and object chains
CQ (obj) |
Provides enhanced functionality for a wrapped CAD primitive. |
Workplane (inPlane[, origin, obj]) |
Defines a coordinate system in space, in which 2-d coordinates can be used. |
2-d Operations¶
Creating 2-d constructs that can be used to create 3 d features.
All 2-d operations require a Workplane object to be created.
Workplane.center (x, y) |
Shift local coordinates to the specified location. |
Workplane.lineTo (x, y[, forConstruction]) |
Make a line from the current point to the provided point |
Workplane.line (xDist, yDist[, forConstruction]) |
Make a line from the current point to the provided point, using |
Workplane.vLine (distance[, forConstruction]) |
Make a vertical line from the current point the provided distance |
Workplane.vLineTo (yCoord[, forConstruction]) |
Make a vertical line from the current point to the provided y coordinate. |
Workplane.hLine (distance[, forConstruction]) |
Make a horizontal line from the current point the provided distance |
Workplane.moveTo ([x, y]) |
Move to the specified point, without drawing. |
Workplane.move ([xDist, yDist]) |
Move the specified distance from the current point, without drawing. |
Workplane.spline (listOfXYTuple[, ...]) |
Create a spline interpolated through the provided points. |
Workplane.threePointArc (point1, point2[, ...]) |
Draw an arc from the current point, through point1, and ending at point2 |
Workplane.rotateAndCopy (matrix) |
Makes a copy of all edges on the stack, rotates them according to the provided matrix, and then attempts to consolidate them into a single wire. |
Workplane.mirrorY () |
Mirror entities around the y axis of the workplane plane. |
Workplane.mirrorX () |
Mirror entities around the x axis of the workplane plane. |
Workplane.wire ([forConstruction]) |
Returns a CQ object with all pending edges connected into a wire. |
Workplane.rect (xLen, yLen[, centered, ...]) |
Make a rectangle for each item on the stack. |
Workplane.circle (radius[, forConstruction]) |
Make a circle for each item on the stack. |
Workplane.polyline (listOfXYTuple[, ...]) |
Create a polyline from a list of points |
Workplane.close () |
End 2-d construction, and attempt to build a closed wire. |
Workplane.rarray (xSpacing, ySpacing, xCount, ...) |
Creates an array of points and pushes them onto the stack. |
3-d Operations¶
Some 3-d operations also require an active 2-d workplane, but some do not.
3-d operations that require a 2-d workplane to be active:
Workplane.cboreHole (diameter, cboreDiameter, ...) |
Makes a counterbored hole for each item on the stack. |
Workplane.cskHole (diameter, cskDiameter, ...) |
Makes a countersunk hole for each item on the stack. |
Workplane.hole (diameter[, depth, clean]) |
Makes a hole for each item on the stack. |
Workplane.extrude (distance[, combine, ...]) |
Use all un-extruded wires in the parent chain to create a prismatic solid. |
Workplane.cut (toCut[, combine, clean]) |
Cuts the provided solid from the current solid, IE, perform a solid subtraction |
Workplane.cutBlind (distanceToCut[, clean]) |
Use all un-extruded wires in the parent chain to create a prismatic cut from existing solid. |
Workplane.cutThruAll ([positive, clean]) |
Use all un-extruded wires in the parent chain to create a prismatic cut from existing solid. |
Workplane.box (length, width, height[, ...]) |
Return a 3d box with specified dimensions for each object on the stack. |
Workplane.union ([toUnion, combine, clean]) |
Unions all of the items on the stack of toUnion with the current solid. |
Workplane.combine ([clean]) |
Attempts to combine all of the items on the stack into a single item. |
3-d operations that do NOT require a 2-d workplane to be active:
CQ.shell (thickness) |
Remove the selected faces to create a shell of the specified thickness. |
CQ.fillet (radius) |
Fillets a solid on the selected edges. |
CQ.split ([keepTop, keepBottom]) |
Splits a solid on the stack into two parts, optionally keeping the separate parts. |
CQ.rotate (axisStartPoint, axisEndPoint, ...) |
Returns a copy of all of the items on the stack rotated through and angle around the axis of rotation. |
CQ.rotateAboutCenter (axisEndPoint, angleDegrees) |
Rotates all items on the stack by the specified angle, about the specified axis |
CQ.translate (vec) |
Returns a copy of all of the items on the stack moved by the specified translation vector. |
File Management and Export¶
CQ.toSvg ([opts]) |
Returns svg text that represents the first item on the stack. |
CQ.exportSvg (fileName) |
Exports the first item on the stack as an SVG file |
importers.importStep (fileName) |
Accepts a file name and loads the STEP file into a cadquery shape | ||
exporters.exportShape (shape, exportType, ...) |
|
Iteration Methods¶
Methods that allow iteration over the stack or objects
Workplane.each (callBackFunction[, ...]) |
Runs the provided function on each value in the stack, and collects the return values into a new CQ object. |
Workplane.eachpoint (callbackFunction[, ...]) |
Same as each(), except each item on the stack is converted into a point before it is passed into the callback function. |
Stack and Selector Methods¶
CadQuery methods that operate on the stack
CQ.all () |
Return a list of all CQ objects on the stack. |
CQ.size () |
Return the number of objects currently on the stack |
CQ.vals () |
get the values in the current list |
CQ.add (obj) |
Adds an object or a list of objects to the stack |
CQ.val () |
Return the first value on the stack |
CQ.first () |
Return the first item on the stack :returns: the first item on the stack. |
CQ.item (i) |
Return the ith item on the stack. |
CQ.last () |
Return the last item on the stack. |
CQ.end () |
Return the parent of this CQ element :rtype: a CQ object :raises: ValueError if there are no more parents in the chain. |
CQ.vertices ([selector]) |
Select the vertices of objects on the stack, optionally filtering the selection. |
CQ.faces ([selector]) |
Select the faces of objects on the stack, optionally filtering the selection. |
CQ.edges ([selector]) |
Select the edges of objects on the stack, optionally filtering the selection. |
CQ.wires ([selector]) |
Select the wires of objects on the stack, optionally filtering the selection. |
CQ.solids ([selector]) |
Select the solids of objects on the stack, optionally filtering the selection. |
CQ.shells ([selector]) |
Select the shells of objects on the stack, optionally filtering the selection. |
CQ.compounds ([selector]) |
Select compounds on the stack, optionally filtering the selection. |
Selectors¶
Objects that filter and select CAD objects. Selectors are used to select existing geometry as a basis for futher operations.
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 |
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 of the prescribed topological type. |
DirectionMinMaxSelector (vector[, ...]) |
Selects objects closest or farthest in the specified direction |
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. |