首页 > 其他分享 >CadQuery API Reference(待完善)

CadQuery API Reference(待完善)

时间:2023-10-23 17:55:21浏览次数:40  
标签:... Sketch Reference CadQuery tag current API Workplane stack

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.

 

  1. Sketch(parent, locs) - 这个函数用于创建一个2D草图。它接受两个参数,parent 是父对象,通常是一个零件或组件,locs 是位置信息,用于确定草图的位置。这个函数的主要作用是创建一个2D平面,用于后续的绘图和建模操作。

  2. Sketch.importDXF(filename[, tol, exclude, ...]) - 这个函数用于导入DXF文件并构建面(face)。DXF是一种常见的二维图形文件格式,该函数可以将DXF文件导入到草图中,并将其构建为一个或多个面。这对于将外部的二维图形数据引入到3D建模软件中非常有用。

  3. Workplane.sketch() - 这个函数用于初始化并返回一个草图对象。它是在工作平面(Workplane)上创建一个新的2D草图,用于在其中进行绘图和建模操作。

  4. Sketch.finalize() - 这个函数用于完成草图的构建并返回其父对象。一旦你完成了在草图中的绘图和建模操作,你可以调用这个函数来完成草图的创建并将其添加到其父对象中。

  5. Sketch.copy() - 这个函数用于创建草图的部分复制。它将当前的草图复制一份,生成一个与原始草图相同的副本。

  6. Sketch.located(loc) - 这个函数用于创建带有新位置信息的草图的部分复制。它复制当前的草图,并将其放置在一个新的位置,以便在不改变原始草图的情况下在不同位置使用。

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

标签:...,Sketch,Reference,CadQuery,tag,current,API,Workplane,stack
From: https://www.cnblogs.com/arwen-xu/p/17783085.html

相关文章

  • 【文心一言】百度千帆 Python 和 JavaScript 调用上下文 API
    接口为:百度ERNIE-Bot-4(邀测)控制台直达链接JavascriptconstAK="urAK"constSK="urSK"constaxios=require("axios").default;letaccess_token="urtoken"varurl='https://aip.baidubce.com/rpc/2.0/ai_custom/v1/w......
  • 支持多用户协作的API测试工具:Apipost
    在当今快速发展的数字化时代,API已成为企业与开发者实现数据互通、应用集成的重要桥梁。然而,随着API数量的不断增加,API开发、调试、测试、文档等工作也变得越来越复杂。为了解决这一痛点,一款名为Apipost的API协同研发工具应运而生。成功案例许多知名的公司和团队都在使用Apipost......
  • Java基础 字节输入流 读取数据 的两个方法API
    public int read()  →  一次读取一个字节数据public int read(byte[] buffer)  →  一次读取一个字节数组的数据,每次读取都会尽可能把数组装满我们创建的数组的长度尽量是1024的整数倍,例如1024*1024*5的长度 ......
  • 视频监控LiteCVR如何通过API接口获取国标GB28181协议接入的实时录像?
    以人工智能为代表的新兴技术,不断驱动着安防等各领域业务层面的创新,同时AI技术的深度应用将成为安防等各领域有效的视频监控解决方案。安防监控视频国标GB28181平台LiteCVR基于云边端一体化架构,具有强大的数据接入、处理及分发能力,可提供视频监控直播、云端录像、云存储、录像检......
  • 如何调用Metabase开放API
    简介:Metabase是什么?在传统企业的数据可视化业务中,通常需要从需求到审批,再到安排开发人员和排期,还要开发人员撰写代码最后再做导出。流程繁琐,参与的人员也多,往往需要几天甚至几周的时间!使用Metabase可以大大节省成本,简单易上手,Metabase把数据分析常用的查询通过一个个易于操......
  • BUG:net::ERR_CONNECTION_REFUSED(前端Vue2、后端FastAPI)
    BUG场景一个前后端分离的项目,前端使用Vue2框架,后端使用FastAPI,前端想要传输图片给后端,使用的相关接口为:'http://10.96.67.161:8081/uploadImg/'后端FastAPI运行的代码为:if__name__=='__main__':uvicorn.run(app="main:app",host="localhost",port=8081,reload=Tr......
  • cadquery创建螺纹thread
    参考来源:https://github.com/CadQuery/cadquery/issues/407importmathimportcadqueryascqdefprofile(base,pitch,h,extra=True):"""pitch螺距Createsatrapezoidalwireforthecrosssectionofthethread.Ifthecrosssectiono......
  • es RESTfull API
    1.4RESTfullAPI一种软件架构风格、设计风格,而不是标准,只是提供了一组设计原则和约束条件。它主要用于客户端和服务器交互类的软件。基于这个风格设计的软件可以更简洁,更有层次,更易于实现缓存等机制。在目前主流的三种Web服务交互方案中,REST相比于SOAP(SimpleObjectAccessprotoco......
  • How to fix Fetch API GET request return an opaque response bug All In One
    HowtofixFetchAPIGETrequestreturnanopaqueresponsebugAllInOneStatusCode:302Foundfetch(`https://www.hulu.com/watch/78974b54-1feb-43ce-9a99-1c1e9e5fce3f`,{mode:"no-cors"}).then(function(response){console.log(`response`,r......
  • 11_常用类和基础API
    ......