CadQuery API Reference(待完善)
CadQuery API Reference
API主要可以分为4个部分
• Sketch – 构建2D草图
• Workplane – 拓扑关系的载体,工作平面
• Selector – 筛选和选择器
• Assembly – 装配体操作
1. Sketch initialization
草图初始化
| 2D sketch. | |
|---|---|
| Import a DXF file and construct face(s) | |
| Initialize and return a sketch | |
| Finish sketch construction and return the parent. | |
| Create a partial copy of the sketch. | |
| Create a partial copy of the sketch with a new location. | |
| 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
草图选择器
| Tag current selection. | |
|---|---|
| Select based on tags. | |
| Reset current selection. | |
| Delete selected object. | |
| Select faces. | |
| Select edges. | |
| Select vertices. |
3. Sketching with faces
在面上绘制
| Construct a face from a wire or edges. | |
|---|---|
| Construct a rectangular face. | |
| Construct a circular face. | |
| Construct an elliptical face. | |
| Construct a trapezoidal face. | |
| Construct a slot-shaped face. | |
| Construct a regular polygonal face. | |
| Construct a polygonal face. | |
| Generate a rectangular array of locations. | |
| Generate a polar array of locations. | |
| Distribute locations along selected edges or wires. | |
| Apply a callback on all applicable entities. | |
| Set current selection to given locations or points. | |
| Generate a convex hull from current selection or all objects. | |
| Offset selected wires or edges. | |
| Add a fillet based on current selection. | |
| Add a chamfer based on current selection. | |
| Remove internal wires. |
4. Sketching with edges and constraints
边的约束
| Add an edge to the sketch. | |
|---|---|
| Construct a segment. | |
| Construct an arc. | |
| Construct a spline edge. | |
| Connect last edge to the first one. | |
| Assemble edges into faces. | |
| Add a constraint. | |
| Solve current constraints and update edge positions. |
5. Initialization
初始化
| Defines a coordinate system in space, in which 2D coordinates can be used. |
|---|
6. 2D Operations
2D操作
所有的2D操作都要基于Workplane对象
| Shift local coordinates to the specified location. | |
|---|---|
| Make a line from the current point to the provided point | |
| Make a line from the current point to the provided point, using dimensions relative to the current point | |
| Make a vertical line from the current point the provided distance | |
| Make a vertical line from the current point to the provided y coordinate. | |
| Make a horizontal line from the current point the provided distance | |
| Make a horizontal line from the current point to the provided x coordinate. | |
| Make a line of the given length, at the given angle from the current point | |
| Make a line from the current point to the given polar coordinates | |
| Move to the specified point, without drawing. | |
| Move the specified distance from the current point, without drawing. | |
| Create a spline interpolated through the provided points (2D or 3D). | |
| Create a spline curve approximating the provided function. | |
| Create a spline surface approximating the provided function. | |
| Draw an arc from the current point, through point1, and ending at point2 | |
| Draw an arc from the current point to endPoint with an arc defined by the sag (sagitta). | |
| Draw an arc from the current point to endPoint with an arc defined by the radius. | |
| Draw an arc as a tangent from the end of the current edge to endpoint. | |
| Mirror entities around the y axis of the workplane plane. | |
| Mirror entities around the x axis of the workplane plane. | |
| Returns a CQ object with all pending edges connected into a wire. | |
| Make a rectangle for each item on the stack. | |
| Make a circle for each item on the stack. | |
| Make an ellipse for each item on the stack. | |
| 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 | |
| Create a polyline from a list of points | |
| End construction, and attempt to build a closed wire. | |
| Creates an array of points and pushes them onto the stack. | |
| Creates a polar array of points and pushes them onto the stack. | |
| Creates a rounded slot for each point on the stack. | |
| Creates a 2D offset wire. | |
| Place the provided sketch(es) based on the current items on the stack. |
7. 3D Operations
3D操作
需要2D活动草图的函数
| Makes a counterbored hole for each item on the stack. | |
|---|---|
| Makes a countersunk hole for each item on the stack. | |
| Makes a hole for each item on the stack. | |
| Use all un-extruded wires in the parent chain to create a prismatic solid. | |
| Cuts the provided solid from the current solid, IE, perform a solid subtraction. | |
| Use all un-extruded wires in the parent chain to create a prismatic cut from existing solid. | |
| Use all un-extruded wires in the parent chain to create a prismatic cut from existing solid. | |
| Return a 3d box with specified dimensions for each object on the stack. | |
| Returns a 3D sphere with the specified radius for each point on the stack. | |
| Returns a 3D wedge with the specified dimensions for each point on the stack. | |
| Returns a cylinder with the specified radius and height for each point on the stack | |
| Unions all of the items on the stack of toUnion with the current solid. | |
| Attempts to combine all of the items on the stack into a single item. | |
| Intersects the provided solid from the current solid. | |
| Make a lofted solid, through the set of wires. | |
| Use all un-extruded wires in the parent chain to create a swept solid. | |
| Extrudes a wire in the direction normal to the plane, but also twists by the specified angle over the length of the extrusion. | |
| Use all un-revolved wires in the parent chain to create a solid. | |
| Returns a 3D text. |
不需要2D活动草图的函数
| Remove the selected faces to create a shell of the specified thickness. | |
|---|---|
| Fillets a solid on the selected edges. | |
| Chamfers a solid on the selected edges. | |
| Splits a solid on the stack into two parts, optionally keeping the separate parts. | |
| Returns a copy of all of the items on the stack rotated through and angle around the axis of rotation. | |
| Rotates all items on the stack by the specified angle, about the specified axis | |
| Returns a copy of all of the items on the stack moved by the specified translation vector. | |
| Mirror a single CQ object. |
8. File Management and Export
| Returns svg text that represents the first item on the stack. | |
|---|---|
| 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 |
|---|---|
| Loads a DXF file into a Workplane. | |
exporters.export(w, fname[, exportType, ...]) |
Export Workplane or Shape to file. |
| Create DXF document from CadQuery objects. |
9. Iteration Methods
| Runs the provided function on each value in the stack, and collects the return values into a new CQ object. | |
|---|---|
| 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
| Return a list of all CQ objects on the stack. | |
|---|---|
| Return the number of objects currently on the stack | |
| get the values in the current list | |
| Adds an object or a list of objects to the stack | |
| Return the first value on the stack. | |
| Return the first item on the stack | |
| Return the ith item on the stack. | |
| Return the last item on the stack. | |
| Return the nth parent of this CQ element | |
| Select the vertices of objects on the stack, optionally filtering the selection. | |
| Select the faces of objects on the stack, optionally filtering the selection. | |
| Select the edges of objects on the stack, optionally filtering the selection. | |
| Select the wires of objects on the stack, optionally filtering the selection. | |
| Select the solids of objects on the stack, optionally filtering the selection. | |
| Select the shells of objects on the stack, optionally filtering the selection. | |
| Select compounds on the stack, optionally filtering the selection. |
11. Selectors
| Selects object nearest the provided point. | |
|---|---|
| Selects objects inside the 3D box defined by 2 points. | |
| A selector that handles selection on the basis of a single direction vector. | |
| Selects objects parallel with the provided direction. | |
| Selects objects aligned with the provided direction. | |
| Filters for objects parallel (or normal) to the specified direction then returns the Nth one. | |
| Select the object(s) with the Nth length | |
| Selects the object(s) with Nth area | |
| Select the object with the Nth radius. | |
| Selects objects perpendicular with the provided direction. | |
| Selects objects having the prescribed geometry type. | |
| Selects objects closest or farthest in the specified direction. | |
| Sorts objects into a list with order determined by the distance of their center projected onto the specified direction. | |
| Base class for selectors that operates with two other selectors. | |
| Intersection selector. | |
| Union selector. | |
| Difference selector. | |
| Inverts the selection of given selector. | |
| Filter lists objects using a simple string syntax. |
12. Assemblies
| Nested assembly of Workplane and Shape objects defining their relative positions. | |
|---|---|
| Add a subassembly to the current assembly. | |
| Save assembly to a file. | |
| Define a new constraint. | |
| Solve the constraints. | |
alias of ConstraintSpec |
|
| Wrapper for the OCCT color object Quantity_ColorRGBA. |

浙公网安备 33010602011771号