# Cheatsheet

A Quick Guide To The Most Commonly Used Functions!
Full API reference | Examples | Install CQ-Editor |
Mode

## 3D Construction

Primitives | Additive | Subtractive
--- | --- | ---
box (length, width, height) | extrude (until) | cutBlind (until)
sphere (radius) | revolve (angleDegrees) | cutThruAll ()
cylinder (height, radius) | loft (ruled) | hole (diameter, depth)
text (txt, fontsize, distance) | sweep (path, isFrenet, transitionMode) | shell (thickness)
^ quickly perform ^ +/-/& boolean ops with (..., combine="a/s/i") or use union/cut/intersect(shape) |  | fillet (radius)
| chamfer (length)

## 2D Construction

rect (xLen, yLen) | circle (radius) | ellipse (x_radius, y_radius)
center (x, y) | moveTo (x, y) | move (xDist, yDist)
lineTo (x, y) | line (xDist, yDist) | polarLine (distance, angle)
vLine (distance) | hLine (distance) | polyline (listOfXYTuple)

## Sketching

rect (w, h) | circle (r) | ellipse (a1, a2)
trapezoid (w, h, a1) | regularPolygon (r, n) | polygon (pts)
fillet (d) | chamfer (d) | finalize ()

## Import/Export

importers.importDXF (path, tol) | importers.importStep ("path")
exporters.export (solid, "path/solid.***") | Where *** can be: svg, step, stl, amf, vrml, json

## Assemblies

Assembly () | add (obj, loc, color)
constrain (***) | solve ()
save ("path/assembly.***") | Where *** can be: step, xml, gltf, vtkjs, vrml

## BREP Terminology

vertex | A single point in space
edge | A connection between two or more vertices along a particular path (called a curve)
wire | A collection of edges that are connected together
face | A set of edges or wires that enclose a surface
shell | A collection of faces that are connected together along some of their edges
solid | A shell that has a closed interior
compound | A collection of solids

## Selector String Modifiers

##

Axis Strings are: X, Y, Z, XY, YZ, XZ

Mod | Description
--- | ---
| | Parallel to = ParallelDirSelector
# | Perpendicular to = PerpendicularDirSelector
+/- | Pos/Neg direction = DirectionSelector
> | Max = DirectionMinMaxSelector(directionMax=True)
< | Min = DirectionMinMaxSelector(directionMax=False)
% | Curve/surface type = TypeSelector
Eg: select the top face (> in Z direction) = `.faces(">Z")`

## Selector Methods

CadQuery selector strings and classes allow filtering to select objects.

Selector Methods | Selector Classes
--- | ---
faces(selector) | NearestToPointSelector(pnt)
edges(selector) | ParallelDirSelector(vector)
vertices(selector) | PerpendicularDirSelector(vector)
solids(selector) | DirectionMinMaxSelector(vector)
shells(selector) | RadiusNthSelector(n)
| AndSelector(selector, selector)
| SumSelector(selector, selector)
| SubtractSelector(selector, selector)
| InverseSelector(selector)

## Workplane Positioning

translate (Vector(x, y, z)) | rotateAboutCenter (Vector(x, y, z), angleDegrees) | rotate (Vector(x, y, z), Vector(x, y, z), angleDegrees)
Position a workplane relative to an existing feature with: .workplane(offset, origin) sets the `offset` perpendicular to the current plane sets the `origin` relative to (0,0) on the current plane

## Named Planes

Direction references refer to the global directions.

Name | xDir | yDir | zDir
--- | --- | --- | ---
XY | +x | +y | +z
YZ | +y | +z | +x
XZ | +x | +z | -y
front | +x | +y | +z
back | -x | +y | -z
left | +z | +y | -x
right | -z | +y | +x
top | +x | -z | +y
bottom | +x | +z | -y

## Core Classes

Class | Description
--- | ---
CQ(obj) | Provides enhanced functionality for a wrapped CAD primitive.
Plane(origin, xDir, normal) | A 2d coordinate system in space, with the x-y axes on the a plane, and a particular point as the origin.
Workplane(inPlane[origin, obj]) | Defines a coordinate system in space, in which 2D coordinates can be used.

## Examples of Filtering Faces

All types of filters work on faces. In most cases, the selector refers to the direction of the normal vector of the face. If a face is not planar, selectors are evaluated at the center of mass of the face. This can lead to results that are quite unexpected.

Selector | Selector Class | Selects | # Objects Returned
--- | --- | --- | ---
+Z | DirectionSelector | Faces with normal in +z direction | 0..many
|Z | ParallelDirSelector | Faces parallel to xy plane | 0..many
-X | DirectionSelector | Faces with normal in neg x direction | 0..many
#Z | PerpendicularDirSelector | Faces perpendicular to z direction | 0..many
%Plane | TypeSelector | Faces of type plane | 0..many
>Y | DirectionMinMaxSelector | Face farthest in the positive y dir | 0 or 1
<Y | DirectionMinMaxSelector | Face farthest in the negative y dir | 0 or 1

## Examples of Filtering Edges

Some filter types are not supported for edges. The selector usually refers to the direction of the edge. Non-linear edges are not selected for any selectors except type (%). Non-linear edges are never returned when these filters are applied.

Selector | Selector Class | Selects | # Objects Returned
--- | --- | --- | ---
+Z | DirectionSelector | Edges aligned in the Z direction | 0..many
|Z | ParallelDirSelector | Edges parallel to z direction | 0..many
-X | DirectionSelector | Edges aligned in neg x direction | 0..many
#Z | PerpendicularDirSelector | Edges perpendicular to z direction | 0..many
%Plane | TypeSelector | Edges type line | 0..many
>Y | DirectionMinMaxSelector | Edges farthest in the positive y dir | 0 or 1
<Y | DirectionMinMaxSelector | Edges farthest in the negative y dir | 0 or 1

## Examples of Filtering Vertices

Only a few of the filter types apply to vertices. The location of the vertex is the subject of the filter.

Selector | Selector Class | Selects
--- | --- | ---
>Y | DirectionMinMaxSelector | Vertices farthest in the +Y dir
<Y | DirectionMinMaxSelector | Vertices farthest in the -Y dir
>>Y[-2] | CenterNthSelector | 2nd farthest vertex in the +Y dir
<<Y[0] | CenterNthSelector | 1st closest vertex in the Y dir