From 32160d16a26de9cbb9a67c4190c36b2166abd0f8 Mon Sep 17 00:00:00 2001 From: adam-urbanczyk Date: Sun, 22 May 2016 20:31:27 +0200 Subject: [PATCH] Symmetric extrude with respect to the workplane Added additional parameter (both=Flase by default) to the extrude method which allows to symmetrically extrude with respect to he current workplane --- cadquery/cq.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) 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 @@ class Workplane(CQ): 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 @@ class Workplane(CQ): :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 @@ class Workplane(CQ): 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 @@ class Workplane(CQ): 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 @@ class Workplane(CQ): 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)