CadQuery API Reference
API主要可以分为4个部分
• Sketch – 构建2D草图
• Workplane – 拓扑关系的载体,工作平面
• Selector – 筛选和选择器
• Assembly – 装配体操作
1. Sketch initialization
草图初始化
Sketch (parent, locs) | 2D sketch. |
---|---|
Sketch.importDXF (filename[, tol, exclude, ...]) |
Import a DXF file and construct face(s) |
Workplane.sketch () |
Initialize and return a sketch |
Sketch.finalize () |
Finish sketch construction and return the parent. |
Sketch.copy () |
Create a partial copy of the sketch. |
Sketch.located (loc) |
Create a partial copy of the sketch with a new location. |
Sketch.moved (loc) |
Create a partial copy of the sketch with moved _faces. |
-
Sketch(parent, locs)
- 这个函数用于创建一个2D草图。它接受两个参数,parent
是父对象,通常是一个零件或组件,locs
是位置信息,用于确定草图的位置。这个函数的主要作用是创建一个2D平面,用于后续的绘图和建模操作。 -
Sketch.importDXF(filename[, tol, exclude, ...])
- 这个函数用于导入DXF文件并构建面(face)。DXF是一种常见的二维图形文件格式,该函数可以将DXF文件导入到草图中,并将其构建为一个或多个面。这对于将外部的二维图形数据引入到3D建模软件中非常有用。 -
Workplane.sketch()
- 这个函数用于初始化并返回一个草图对象。它是在工作平面(Workplane)上创建一个新的2D草图,用于在其中进行绘图和建模操作。 -
Sketch.finalize()
- 这个函数用于完成草图的构建并返回其父对象。一旦你完成了在草图中的绘图和建模操作,你可以调用这个函数来完成草图的创建并将其添加到其父对象中。 -
Sketch.copy()
- 这个函数用于创建草图的部分复制。它将当前的草图复制一份,生成一个与原始草图相同的副本。 -
Sketch.located(loc)
- 这个函数用于创建带有新位置信息的草图的部分复制。它复制当前的草图,并将其放置在一个新的位置,以便在不改变原始草图的情况下在不同位置使用。 -
Sketch.moved(loc)
- 这个函数用于创建带有移动后的面(_faces)的草图的部分复制。它复制当前的草图,并移动其中的面或对象,以实现位置的变化。这可以用于在不同位置或方向上重复使用草图元素。
2. Sketch selection
草图选择器
Sketch.tag (tag) | Tag current selection. |
---|---|
Sketch.select (*tags) |
Select based on tags. |
Sketch.reset () |
Reset current selection. |
Sketch.delete () |
Delete selected object. |
Sketch.faces ([s, tag]) |
Select faces. |
Sketch.edges ([s, tag]) |
Select edges. |
Sketch.vertices ([s, tag]) |
Select vertices. |
3. Sketching with faces
在面上绘制
Sketch.face (b[, angle, mode, tag, ...]) | Construct a face from a wire or edges. |
---|---|
Sketch.rect (w, h[, angle, mode, tag]) |
Construct a rectangular face. |
Sketch.circle (r[, mode, tag]) |
Construct a circular face. |
Sketch.ellipse (a1, a2[, angle, mode, tag]) |
Construct an elliptical face. |
Sketch.trapezoid (w, h, a1[, a2, angle, ...]) |
Construct a trapezoidal face. |
Sketch.slot (w, h[, angle, mode, tag]) |
Construct a slot-shaped face. |
Sketch.regularPolygon (r, n[, angle, mode, tag]) |
Construct a regular polygonal face. |
Sketch.polygon (pts[, angle, mode, tag]) |
Construct a polygonal face. |
Sketch.rarray (xs, ys, nx, ny) |
Generate a rectangular array of locations. |
Sketch.parray (r, a1, da, n[, rotate]) |
Generate a polar array of locations. |
Sketch.distribute (n[, start, stop, rotate]) |
Distribute locations along selected edges or wires. |
Sketch.each (callback[, mode, tag, ...]) |
Apply a callback on all applicable entities. |
Sketch.push (locs[, tag]) |
Set current selection to given locations or points. |
Sketch.hull ([mode, tag]) |
Generate a convex hull from current selection or all objects. |
Sketch.offset (d[, mode, tag]) |
Offset selected wires or edges. |
Sketch.fillet (d) |
Add a fillet based on current selection. |
Sketch.chamfer (d) |
Add a chamfer based on current selection. |
Sketch.clean () |
Remove internal wires. |
4. Sketching with edges and constraints
边的约束
Sketch.edge (val[, tag, forConstruction]) | Add an edge to the sketch. |
---|---|
Sketch.segment (...) |
Construct a segment. |
Sketch.arc (...) |
Construct an arc. |
Sketch.spline (...) |
Construct a spline edge. |
Sketch.close ([tag]) |
Connect last edge to the first one. |
Sketch.assemble ([mode, tag]) |
Assemble edges into faces. |
Sketch.constrain (...) |
Add a constraint. |
Sketch.solve () |
Solve current constraints and update edge positions. |
5. Initialization
初始化
Workplane (, obj=None)) | Defines a coordinate system in space, in which 2D coordinates can be used. |
---|
6. 2D Operations
2D操作
所有的2D操作都要基于Workplane对象
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 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 a 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. |
Workplane.placeSketch (*sketches) |
Place the provided sketch(es) based on the current items on the stack. |
7. 3D Operations
3D操作
需要2D活动草图的函数
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, tol]) |
Cuts the provided solid from the current solid, IE, perform a solid subtraction. |
Workplane.cutBlind (until[, clean, both, 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.wedge (dx, dy, dz, xmin, zmin, ...) |
Returns a 3D wedge with the specified dimensions 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, tol]) |
Intersects the provided solid from the current solid. |
Workplane.loft ([ruled, combine, clean]) |
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[, ...]) |
Returns a 3D text. |
不需要2D活动草图的函数
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. |
8. 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, ...]) |
Loads a DXF file into a Workplane. |
exporters.export (w, fname[, exportType, ...]) |
Export Workplane or Shape to file. |
occ_impl.exporters.dxf.DxfDocument ([...]) |
Create DXF document from CadQuery objects. |
9. Iteration Methods
Workplane.each (callback[, ...]) | 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. |
10. Stack and Selector Methods
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 |
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 |
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. |
11. Selectors
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. |
12. Assemblies
Assembly ([obj, loc, name, color, metadata]) | Nested assembly of Workplane and Shape objects defining their relative positions. |
---|---|
Assembly.add () |
Add a subassembly to the current assembly. |
Assembly.save (path[, exportType, mode, ...]) |
Save assembly to a file. |
Assembly.constrain () |
Define a new constraint. |
Assembly.solve ([verbosity]) |
Solve the constraints. |
Constraint |
alias of ConstraintSpec |
Color () |
Wrapper for the OCCT color object Quantity_ColorRGBA. |