CadQuery API Reference

The CadQuery API is made up of 2 main objects:

  • Workplane -- Wraps a topological entity and provides a 2D modelling context.

  • Selector -- Filter and select things

This page lists methods of these objects grouped by functional area

参考

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

Workplane()

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

2D Operations

Creating 2D constructs that can be used to create 3D features.

All 2D 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 dimensions relative to the current point

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.hLineTo(xCoord[, forConstruction])

Make a horizontal line from the current point to the provided x coordinate.

Workplane.polarLine(distance, angle[, ...])

Make a line of the given length, at the given angle from the current point

Workplane.polarLineTo(distance, angle[, ...])

Make a line from the current point to the given polar coordinates

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[, tangents, ...])

Create a spline interpolated through the provided points (2D or 3D).

Workplane.parametricCurve(func[, N, start, ...])

Create a spline curve approximating the provided function.

Workplane.parametricSurface(func[, N, ...])

Create a spline surface approximating the provided function.

Workplane.threePointArc(point1, point2[, ...])

Draw an arc from the current point, through point1, and ending at point2

Workplane.sagittaArc(endPoint, sag[, ...])

Draw an arc from the current point to endPoint with an arc defined by the sag (sagitta).

Workplane.radiusArc(endPoint, radius[, ...])

Draw an arc from the current point to endPoint with an arc defined by the radius.

Workplane.tangentArcPoint(endpoint[, ...])

Draw an arc as a tangent from the end of the current edge to endpoint.

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.ellipse(x_radius, y_radius[, ...])

Make an ellipse for each item on the stack.

Workplane.ellipseArc(x_radius, y_radius[, ...])

Draw an elliptical arc with x and y radiuses either with start point at current point or or current point being the center of the arc

Workplane.polyline(listOfXYTuple[, ...])

Create a polyline from a list of points

Workplane.close()

End 2D construction, and attempt to build a closed wire.

Workplane.rarray(xSpacing, ySpacing, xCount, ...)

Creates an array of points and pushes them onto the stack.

Workplane.polarArray(radius, startAngle, ...)

Creates an polar array of points and pushes them onto the stack.

Workplane.slot2D(length, diameter[, angle])

Creates a rounded slot for each point on the stack.

Workplane.offset2D(d[, kind, forConstruction])

Creates a 2D offset wire.

3D Operations

Some 3D operations also require an active 2D workplane, but some do not.

3D operations that require a 2D 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(until[, combine, clean, ...])

Use all un-extruded wires in the parent chain to create a prismatic solid.

Workplane.cut(toCut[, clean])

Cuts the provided solid from the current solid, IE, perform a solid subtraction

Workplane.cutBlind(until[, clean, taper])

Use all un-extruded wires in the parent chain to create a prismatic cut from existing solid.

Workplane.cutThruAll([clean, taper])

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.sphere(radius[, direct, angle1, ...])

Returns a 3D sphere with the specified radius for each point on the stack

Workplane.cylinder(height, radius[, direct, ...])

Returns a cylinder with the specified radius and height for each point on the stack

Workplane.union([toUnion, clean, glue, tol])

Unions all of the items on the stack of toUnion with the current solid.

Workplane.combine([clean, glue, tol])

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

Workplane.intersect(toIntersect[, clean])

Intersects the provided solid from the current solid.

Workplane.loft([filled, ruled, combine])

Make a lofted solid, through the set of wires.

Workplane.sweep(path[, multisection, ...])

Use all un-extruded wires in the parent chain to create a swept solid.

Workplane.twistExtrude(distance, angleDegrees)

Extrudes a wire in the direction normal to the plane, but also twists by the specified angle over the length of the extrusion

Workplane.revolve([angleDegrees, axisStart, ...])

Use all un-revolved wires in the parent chain to create a solid.

Workplane.text(txt, fontsize, distance[, ...])

Create a 3D text

3D operations that do NOT require a 2D workplane to be active:

Workplane.shell(thickness[, kind])

Remove the selected faces to create a shell of the specified thickness.

Workplane.fillet(radius)

Fillets a solid on the selected edges.

Workplane.chamfer(length[, length2])

Chamfers a solid on the selected edges.

Workplane.split()

Splits a solid on the stack into two parts, optionally keeping the separate parts.

Workplane.rotate(axisStartPoint, ...)

Returns a copy of all of the items on the stack rotated through and angle around the axis of rotation.

Workplane.rotateAboutCenter(axisEndPoint, ...)

Rotates all items on the stack by the specified angle, about the specified axis

Workplane.translate(vec)

Returns a copy of all of the items on the stack moved by the specified translation vector.

Workplane.mirror([mirrorPlane, ...])

Mirror a single CQ object.

File Management and Export

Workplane.toSvg([opts])

Returns svg text that represents the first item on the stack.

Workplane.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 Workplane

importers.importDXF(filename[, tol, exclude])

Loads a DXF file into a cadquery Workplane.

exporters.export(w, fname[, exportType, ...])

Export Wokrplane or Shape to file.

Iteration Methods

Methods that allow iteration over the stack or objects

Workplane.each(callback[, useLocalCoordinates])

Runs the provided function on each value in the stack, and collects the return values into a new CQ object.

Workplane.eachpoint(callback[, ...])

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

Workplane.all()

Return a list of all CQ objects on the stack.

Workplane.size()

Return the number of objects currently on the stack

Workplane.vals()

get the values in the current list

Workplane.add()

Adds an object or a list of objects to the stack

Workplane.val()

Return the first value on the stack.

Workplane.first()

Return the first item on the stack :returns: the first item on the stack.

Workplane.item(i)

Return the ith item on the stack.

Workplane.last()

Return the last item on the stack.

Workplane.end([n])

Return the nth parent of this CQ element :type n: int :param n: number of ancestor to return (default: 1) :rtype: a CQ object :raises: ValueError if there are no more parents in the chain.

Workplane.vertices([selector, tag])

Select the vertices of objects on the stack, optionally filtering the selection.

Workplane.faces([selector, tag])

Select the faces of objects on the stack, optionally filtering the selection.

Workplane.edges([selector, tag])

Select the edges of objects on the stack, optionally filtering the selection.

Workplane.wires([selector, tag])

Select the wires of objects on the stack, optionally filtering the selection.

Workplane.solids([selector, tag])

Select the solids of objects on the stack, optionally filtering the selection.

Workplane.shells([selector, tag])

Select the shells of objects on the stack, optionally filtering the selection.

Workplane.compounds([selector, tag])

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 further 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 direction vector.

ParallelDirSelector(vector[, tolerance])

Selects objects parallel with the provided direction.

DirectionSelector(vector[, tolerance])

Selects objects aligned with the provided 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

RadiusNthSelector(n[, directionMax, tolerance])

Select the object with the Nth radius.

PerpendicularDirSelector(vector[, tolerance])

Selects objects perpendicular with the provided direction.

TypeSelector(typeString)

Selects objects having the prescribed geometry type.

DirectionMinMaxSelector(vector[, ...])

Selects objects closest or farthest in the specified direction.

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

Sorts objects into a list with order determined by the distance of their center projected onto 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.

Assemblies

Workplane and Shape objects can be connected together into assemblies

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

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

Assembly.add()

Add a subassembly to the current assembly.

Assembly.save(path[, exportType])

save as STEP or OCCT native XML file

Assembly.constrain()

Define a new constraint.

Assembly.solve()

Solve the constraints.

Constraint(objects, args, sublocs, kind[, param])

Geometrical constraint between two shapes of an assembly.

Color()

Wrapper for the OCCT color object Quantity_ColorRGBA.