The Sketch.chamfer()
method in CadQuery
allows you to create chamfers on 2D sketches.
chamfer(distance, point=None, edges=None, add_distance=False)
distance
(float): The distance of the chamfer.point
(tuple, optional): The origin point of the chamfer.edges
(list, optional): A list of edges to chamfer.add_distance
(bool, optional): Whether to add the chamfer distance or subtract it.The distance of the chamfer is specified by the distance
parameter. This value can be either positive or negative. When it is positive, the chamfer will be created inside the sketch, and when it is negative, the chamfer will be created outside the sketch.
The point
parameter is an optional parameter that allows you to specify the origin point of the chamfer.
The edges
parameter is an optional parameter that allows you to specify a list of edges to chamfer. If this parameter is not specified, all edges of the sketch will be chamfered.
The add_distance
parameter is a boolean parameter that allows you to specify whether to add or subtract the chamfer distance. By default, it is set to False
which means that the distance will be subtracted from the edges.
import cadquery as cq
# create the sketch
sketch = cq.Workplane("XY").box(1, 1, 1).faces("+Z").workplane()
# chamfer all the edges by 0.1
sketch = sketch.chamfer(0.1)
# extrude the sketch
result = sketch.extrude(1)
show_object(result)
In this example, we create a simple sketch of a box and chamfer all the edges by 0.1.
import cadquery as cq
# create the sketch
sketch = cq.Workplane("XY").box(1, 1, 1).faces("+Z").workplane()
# chamfer only the selected edges by 0.1
sketch = sketch.edges("|Y").chamfer(0.1)
# extrude the sketch
result = sketch.extrude(1)
show_object(result)
In this example, we create a simple sketch of a box and chamfer only the edges parallel to the y-axis by 0.1.
import cadquery as cq
# create the sketch
sketch = cq.Workplane("XY").box(1, 1, 1).faces("+Z").workplane()
# chamfer all the edges except for the ones parallel to the x-axis and y-axis by 0.1
sketch = sketch.edges("|Y").normalize().chamfer(0.1)
# extrude the sketch
result = sketch.extrude(1)
show_object(result)
In this example, we create a simple sketch of a box and chamfer all the edges except for the ones parallel to the x-axis and y-axis by 0.1.