diff --git a/cadquery/cq.py b/cadquery/cq.py index 2ac9d7e..b2d3a50 100644 --- a/cadquery/cq.py +++ b/cadquery/cq.py @@ -1967,7 +1967,7 @@ def twistExtrude(self, distance, angleDegrees, combine=True, clean=True): if clean: newS = newS.clean() return newS - def extrude(self, distance, combine=True, clean=True): + def extrude(self, distance, combine=True, clean=True, both=False): """ Use all un-extruded wires in the parent chain to create a prismatic solid. @@ -1975,6 +1975,7 @@ def extrude(self, distance, combine=True, clean=True): :type distance: float, negative means opposite the normal direction :param boolean combine: True to combine the resulting solid with parent solids if found. :param boolean clean: call :py:meth:`clean` afterwards to have a clean shape + :param boolean both: extrude in both directions symmetrically :return: a CQ object with the resulting solid selected. extrude always *adds* material to a part. @@ -1990,8 +1991,9 @@ def extrude(self, distance, combine=True, clean=True): Support for non-prismatic extrusion ( IE, sweeping along a profile, not just perpendicular to the plane extrude to surface. this is quite tricky since the surface selected may not be planar - """ - r = self._extrude(distance) # returns a Solid (or a compound if there were multiple) + """ + r = self._extrude(distance,both=both) # returns a Solid (or a compound if there were multiple) + if combine: newS = self._combineWithBase(r) else: @@ -2254,11 +2256,12 @@ def loft(self, filled=True, ruled=False, combine=True): return self.newObject([r]) - def _extrude(self, distance): + def _extrude(self, distance, both=False): """ Make a prismatic solid from the existing set of pending wires. :param distance: distance to extrude + :param boolean both: extrude in both directions symmetrically :return: a FreeCAD solid, suitable for boolean operations. This method is a utility method, primarily for plugin and internal use. @@ -2305,6 +2308,10 @@ def _extrude(self, distance): for ws in wireSets: thisObj = Solid.extrudeLinear(ws[0], ws[1:], eDir) toFuse.append(thisObj) + + if both: + thisObj = Solid.extrudeLinear(ws[0], ws[1:], eDir.multiply(-1.)) + toFuse.append(thisObj) return Compound.makeCompound(toFuse) diff --git a/tests/TestCadQuery.py b/tests/TestCadQuery.py index 7947ee1..f12165a 100644 --- a/tests/TestCadQuery.py +++ b/tests/TestCadQuery.py @@ -1387,3 +1387,27 @@ def testEnclosure(self): result =topOfLid.union(bottom) self.saveModel(result) + + def testExtrude(self): + """ + Test symmetric extrude + """ + r = 1. + h = 1. + decimal_places = 9. + + #extrude symmetrically + s = Workplane("XY").circle(r).extrude(h,both=True) + + top_face = s.faces(">Z") + bottom_face = s.faces("