From 48cd1a78f23bc28b3293f67447397aeb2c2951a3 Mon Sep 17 00:00:00 2001 From: bweissinger Date: Sun, 1 Sep 2019 18:40:09 -0500 Subject: [PATCH] Add rounded slot function --- cadquery/cq.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/cadquery/cq.py b/cadquery/cq.py index cd00c9b7..ed70a48f 100644 --- a/cadquery/cq.py +++ b/cadquery/cq.py @@ -1346,6 +1346,48 @@ class Workplane(CQ): newCenter = p + Vector(xDist, yDist, 0) return self.newObject([self.plane.toWorldCoords(newCenter)]) + def slot(self, length, diameter, angle): + """ + Creates a rounded slot for each point on the stack. + + :param diameter: desired diameter, or width, of slot + :param length: desired end to end length of slot + :param angle: angle of slot in degrees, with 0 being along x-axis + :return: a new CQ object with the created wires on the stack + + Can be used to create arrays of slots, such as in cooling applications: + + result = cq.Workplane("XY").box(10,25,1).rarray(1,2,1,10).slot(8,1,0).cutThruAll() + """ + + def _makeslot(pnt): + """ + Inner function that is used to create a slot for each point/object on the workplane + :param pnt: The center point for the slot + :return: A CQ object representing a slot + """ + + radius = diameter/2 + centerPoint = self.plane.toWorldCoords(pnt) + + p1 = centerPoint.add(Vector((-length/2) + radius, diameter/2)) + p2 = p1.add(Vector(length - diameter, 0)) + p3 = p1.add(Vector(length - diameter, -diameter)) + p4 = p1.add(Vector(0, -diameter)) + arc1 = p2.add(Vector(radius, -radius)) + arc2 = p4.add(Vector(-radius, radius)) + + edges=[(Edge.makeLine(p1,p2))] + edges.append(Edge.makeThreePointArc(p2, arc1, p3)) + edges.append(Edge.makeLine(p3, p4)) + edges.append(Edge.makeThreePointArc(p4, arc2, p1)) + + slot = Wire.assembleEdges(edges) + + return slot.rotate(centerPoint, centerPoint.add(Vector(0,0,1)), angle) + + return self.eachpoint(_makeslot, True) + def spline(self, listOfXYTuple, tangents=None, periodic=False, forConstruction=False, includeCurrent=False, makeWire=False): """