diff --git a/CadQuery/Libs/cadquery/CQ.py b/CadQuery/Libs/cadquery/CQ.py index d666659..708f6de 100644 --- a/CadQuery/Libs/cadquery/CQ.py +++ b/CadQuery/Libs/cadquery/CQ.py @@ -795,6 +795,44 @@ class CQ(object): solid.wrapped = s.wrapped return self.newObject([s]) + def chamfer(self, length, length2 = None): + """ + Chamfers a solid on the selected edges. + + The edges on the stack are chamfered. The solid to which the + edges belong must be in the parent chain of the selected + edges. + + Optional parameter `length2` can be supplied with a different + value than `length` for a chamfer that is shorter on one side + longer on the other side. + + :param length: the length of the fillet, must be greater than zero + :param length2: optional parameter for asymmetrical chamfer + :type length: positive float + :type length2: positive float + :raises: ValueError if at least one edge is not selected + :raises: ValueError if the solid containing the edge is not in the chain + :returns: cq object with the resulting solid selected. + + This example will create a unit cube, with the top edges chamfered:: + + s = Workplane("XY").box(1,1,1).faces("+Z").chamfer(0.1) + + This example will create chamfers longer on the sides:: + + s = Workplane("XY").box(1,1,1).faces("+Z").chamfer(0.2, 0.1) + """ + solid = self.findSolid() + + edgeList = self.edges().vals() + if len(edgeList) < 1: + raise ValueError("Chamfer requires that edges be selected") + + s = solid.chamfer(length, length2, edgeList) + + solid.wrapped = s.wrapped + return self.newObject([s]) class Workplane(CQ): """ @@ -2299,11 +2337,11 @@ class Workplane(CQ): (xp, yp, zp) = pnt.toTuple() if centered[0]: - xp -= radius + xp -= radius * direct.x if centered[1]: - yp -= radius + yp -= radius * direct.y if centered[2]: - zp -= radius + zp -= radius * direct.z return Solid.makeSphere(radius, Vector(xp, yp, zp), direct, angle1, angle2, angle3) diff --git a/CadQuery/Libs/cadquery/cheatsheet/cadquery_cheatsheet.html b/CadQuery/Libs/cadquery/cheatsheet/cadquery_cheatsheet.html new file mode 100644 index 0000000..bb58252 --- /dev/null +++ b/CadQuery/Libs/cadquery/cheatsheet/cadquery_cheatsheet.html @@ -0,0 +1,404 @@ + + + + CadQuery Cheatsheet + + + + + +
+
+

Documentation

+ +
+
+

BREP Terminology


+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
vertexA single point in space
edgeA connection between two or more vertices along a particular path (called a curve)
wireA collection of edges that are connected together
faceA set of edges or wires that enclose a surface
shellA collection of faces that are connected together along some of their edges
solidA shell that has a closed interior
compoundA collection of solids
+
+
+

Named Planes


+ Available named planes are as follows. Direction references refer to the global directions. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NamexDiryDirzDir
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


+ + + + + + + + + + + + + + + + + +
ClassDescription
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 2-d coordinates can be used.
+
+
+
+
+

Selector Methods


+ CadQuery selector strings allow filtering various types of object lists. + Most commonly, Edges, Faces, and Vertices are used, but all objects types can be filtered.
+ + + + + + + + + + + + + + + + + + + + + + + + +
Selector MethodDescription
CQ.faces(selector=None)Select the faces of objects on the stack, optionally filtering the selection.
CQ.edges(selector=None)Select the edges of objects on the stack, optionally filtering the selection.
CQ.vertices(selector=None)Select the vertices of objects on the stack, optionally filtering the selection.
CQ.solids(selector=None)Select the solids of objects on the stack, optionally filtering the selection.
CQ.shells(selector=None)Select the shells of objects on the stack, optionally filtering the selection.
+
+
+

Selector Classes


+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ClassDescription
NearestToPointSelector(pnt)Selects object nearest the provided point.
ParallelDirSelector(vector[tolerance])Selects objects parallel with the provided direction.
DirectionSelector(vector[tolerance])Selects objects aligned with the provided direction.
PerpendicularDirSelector(vector[tolerance])Selects objects perpendicular with the provided direction.
TypeSelector(typeString)Selects objects of the prescribed topological type.
DirectionMinMaxSelector(vector[directionMax])Selects objects closest or farthest in the specified direction.
StringSyntaxSelector(selectorString)Filter lists objects using a simple string syntax.
+
+
+

Selector String Modifiers


+ Selectors are a complex topic: see CadQuery String Selectors for more information.
+ Axis Strings are: X, Y, Z, XY, YZ, XZ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ModifierDescription
|Parallel to (same as ParallelDirSelector). Can return multiple objects.
#Perpendicular to (same as PerpendicularDirSelector)
+Positive direction (same as DirectionSelector)
-Negative direction (same as DirectionSelector)
>Maximize (same as DirectionMinMaxSelector with directionMax=True)
<Minimize (same as DirectionMinMaxSelector with directionMax=False)
%Curve/surface type (same as TypeSelector)
+
+
+

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. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
SelectorSelector ClassSelects# Objects Returned
+ZDirectionSelectorFaces with normal in +z direction0 or 1
|ZParallelDirSelectorFaces parallel to xy plane0..many
-XDirectionSelectorFaces with normal in neg x direction0..many
#ZPerpendicularDirSelectorFaces perpendicular to z direction0..many
%PlaneTypeSelectorFaces of type plane0..many
>YDirectionMinMaxSelectorFace farthest in the positive y dir0 or 1
<YDirectionMinMaxSelectorFace farthest in the negative y dir0 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. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
SelectorSelector ClassSelects# Objects Returned
+ZDirectionSelectorEdges aligned in the Z direction0..many
|ZParallelDirSelectorEdges parallel to z direction0..many
-XDirectionSelectorEdges aligned in neg x direction0..many
#ZPerpendicularDirSelectorEdges perpendicular to z direction0..many
%PlaneTypeSelectorEdges type line0..many
>YDirectionMinMaxSelectorEdges farthest in the positive y dir0 or 1
<YDirectionMinMaxSelectorEdges farthest in the negative y dir0 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. + + + + + + + + + + + + + + + + + + + +
SelectorSelector ClassSelects# Objects Returned
>YDirectionMinMaxSelectorVertices farthest in the positive y dir0 or 1
<YDirectionMinMaxSelectorVertices farthest in the negative y dir0 or 1
+
+
+ + diff --git a/CadQuery/Libs/cadquery/freecad_impl/shapes.py b/CadQuery/Libs/cadquery/freecad_impl/shapes.py index 03e34b5..e0f2ecf 100644 --- a/CadQuery/Libs/cadquery/freecad_impl/shapes.py +++ b/CadQuery/Libs/cadquery/freecad_impl/shapes.py @@ -812,6 +812,21 @@ class Solid(Shape): nativeEdges = [e.wrapped for e in edgeList] return Shape.cast(self.wrapped.makeFillet(radius, nativeEdges)) + def chamfer(self, length, length2, edgeList): + """ + Chamfers the specified edges of this solid. + :param length: length > 0, the length (length) of the chamfer + :param length2: length2 > 0, optional parameter for asymmetrical chamfer. Should be `None` if not required. + :param edgeList: a list of Edge objects, which must belong to this solid + :return: Chamfered solid + """ + nativeEdges = [e.wrapped for e in edgeList] + # note: we prefer 'length' word to 'radius' as opposed to FreeCAD's API + if length2: + return Shape.cast(self.wrapped.makeChamfer(length, length2, nativeEdges)) + else: + return Shape.cast(self.wrapped.makeChamfer(length, nativeEdges)) + def shell(self, faceList, thickness, tolerance=0.0001): """ make a shelled solid of given by removing the list of faces